+ 2
Why java doesn't support multiple inheritance?
6 Antworten
+ 9
Because interfaces specify only what the class is doing, not how it is doing it.
The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can't choose which one to pick
https://www.sololearn.com/discuss/780139/?ref=app
+ 5
Some say it is because of The Diamond Problem. Suppose classes C and B are derived from Class A, and class D extends both C and B. If C and B override the foo() method of A, which foo() will D use? C's or B's ?
Note that C++, Python and Common LISP support multiple inheritance, and each solves the diamond problem in its own way.
+ 4
Java solves the problem by not allowing multiple inheritance: in Java, no class can have more than one superclass. So there can never be diamond problem ambiguity in Java.
+ 1
It is supported in c++ but not in Java since it lead to really messy code, inheritance is a mechanism to represent hierarchy in SUD, if you have class that inherited from several different classes, it is really hard to understand system structure. Imagine that you have class coach witch inherited from furniture(it is ok) and from cars (they also have a leather cover). In big systems it may have really bad results...
0
what if we have same unimplemented methods in 2 interfaces which we are going to implement... do program gives error or executes successfully..??
0
what about java??