Why is multiple inheritances not supported in Java ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Why is multiple inheritances not supported in Java ?

normally c++ and other language support multiple inheritance. but Java doesn't.

10th Dec 2016, 12:26 AM
Saikat Basak
Saikat Basak - avatar
1 Answer
+ 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.
10th Dec 2016, 12:27 AM
Saikat Basak
Saikat Basak - avatar