+ 2

Why java doesn't support multiple inheritance?

10th Dec 2017, 10:11 AM
Raghavendra Phayde
Raghavendra Phayde - avatar
6 Answers
+ 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
10th Dec 2017, 10:19 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 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.
10th Dec 2017, 10:37 AM
Eric Blinkidu
Eric Blinkidu - avatar
+ 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.
10th Dec 2017, 11:10 AM
Eric Blinkidu
Eric Blinkidu - avatar
+ 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...
10th Dec 2017, 11:15 AM
Dima Makieiev
Dima Makieiev - avatar
0
what if we have same unimplemented methods in 2 interfaces which we are going to implement... do program gives error or executes successfully..??
10th Dec 2017, 10:25 AM
Raghavendra Phayde
Raghavendra Phayde - avatar
0
what about java??
10th Dec 2017, 10:43 AM
Raghavendra Phayde
Raghavendra Phayde - avatar