+ 5
Why is multiple inheritances not supported in Java ?
normally c++ and other language support multiple inheritance. but Java doesn't.
1 Réponse
+ 8
C++ , Common lisp and few other languages supports multiple inheritance while java doesn’t support it. It is just to remove ambiguity, because multiple inheritance can cause ambiguity in few scenarios. One of the most common scenario is Diamond problem.
What is diamond problem?
Consider the below diagram which shows multiple inheritance as Class D extends both Class B & C. Now lets assume we have a method in class A and class B & C overrides that method in their own way. Wait!! 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.