+ 13
Why Java does not support multiple inheritance??
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.
+ 3
@alice nice one
+ 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.
+ 2
Also, it does. Just use default keyword in interfaces and you can inherit multiply all you like.
+ 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/
+ 1
multiple inheritance can create ambiguity.. ambiguity can arise when two or more classes having same name
0
the comma ( , )character unfortunately not used during inheritance so does not works..