Why java doesn't have multiple inheritance through classes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why java doesn't have multiple inheritance through classes?

5th Oct 2019, 2:01 PM
Yash
Yash - avatar
3 Answers
+ 2
Consider a example of multiple inheritance , where A has 2 child class let's say B and C. And D is child class of B and C. Now if D wants to inherit any property of A then there are 2 paths either through B or through C. Compiler here gets confused which path to pick. The case of multiple inheritance leads to ambiguity. This is why java doesn't support multiple inheritance. However, it does support multi-level inheritance.
5th Oct 2019, 2:06 PM
Chetali Shah
Chetali Shah - avatar
+ 3
As Chetali Shah Java is built in that manner, and prevents diamond inheritance. https://www.google.com/amp/s/www.freecodecamp.org/news/multiple-inheritance-in-c-and-the-diamond-problem-7c12a9ddbbec/amp/ C++ allows you do it, at your own risk. Typically I avoid using diamond inheritance.
5th Oct 2019, 2:15 PM
Manual
Manual - avatar
+ 3
A program cant make a decision unless it's been told how and that's what the problem is with the diamond pattern.. your asking the program to solve possible ambiguity between 2 methods without knowing why even the human brain cant do that unless theres a reason. Its similar to me asking you if I use your phone should I call john or Kevin? Without you knowing why?
5th Oct 2019, 3:02 PM
D_Stark
D_Stark - avatar