+ 13

Why Java does not support multiple inheritance??

11th Oct 2017, 1:22 PM
Chandrakant More
Chandrakant More - avatar
8 odpowiedzi
+ 11
For example, classes B & C extend class A. Class D extends both classes B & C. Now lets assume we have a method in class A and class B & C overrides that method in their own way. But here the problem comes – Because D is extending both B & C so if D wants to use the same method which method would be called (the overridden method of B or the overridden method of C). Ambiguity. That’s the main reason why Java doesn’t support multiple inheritance.
11th Oct 2017, 1:42 PM
Alice
Alice - avatar
+ 3
@alice nice one
11th Oct 2017, 3:18 PM
Muhammadnoor Hassansheikh
Muhammadnoor Hassansheikh - avatar
+ 3
First lets nail this point. This itself is a point of discussion, whether java supports multiple inheritance or not. Some say, it supports using interface. No. There is no support for multiple inheritance in java. If you do not believe my words, read the above paragraph again and those are words of the father of Java. This story of supporting multiple inheritance using interface is what we developers cooked up. Interface gives flexibility than concrete classes and we have option to implement multiple interface using single class. This is by agreement we are adhering to two blueprints to create a class. This is trying to get closer to multiple inheritance. What we do is implement multiple interface, here we are not extending (inheriting) anything. The implementing class is the one that is going to add the properties and behavior. It is not getting the implementation free from the parent classes. I would simply say, there is no support for multiple inheritance in java.
12th Oct 2017, 5:50 PM
Ravish kumar singh
Ravish kumar singh - avatar
+ 2
Also, it does. Just use default keyword in interfaces and you can inherit multiply all you like.
11th Oct 2017, 7:49 PM
1of3
1of3 - avatar
+ 2
java does not support multiple inheritance because it does not meet object oriented specification. Due to ambiguity problem will arise if two or more superclass have the same method name, and the super keyword will not be able to decide which superclass to call. so we use interface to solve this problem. You can see more here :-http://crbtech.in/Java-Training/java-doesnt-support-multiple-inheritance/
12th Oct 2017, 6:11 AM
mayur kohli
mayur kohli - avatar
+ 1
multiple inheritance can create ambiguity.. ambiguity can arise when two or more classes having same name
13th Jul 2018, 3:13 PM
deeksha
deeksha - avatar
0
the comma ( , )character unfortunately not used during inheritance so does not works..
30th Jul 2018, 1:56 PM
Faizur Rahman.A
Faizur Rahman.A - avatar