Intresting, only c++ alows ineritance from multiply parents... Anybody knows why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Intresting, only c++ alows ineritance from multiply parents... Anybody knows why?

30th Nov 2016, 12:31 AM
Admirim Ymeri
Admirim Ymeri - avatar
2 Answers
+ 10
Class A and B have a method that they inherited from class C and they have overriden it in two different ways. Now you make a new class D that has as parents A and B. If you call that method in c++ it would result in an error. I think in other languages like java they wanted to avoid that without you having to prevent it ? In Java you can do class A extends B. Class B extends C. This is like having 2 parents. You can also implement multiple interfaces.
30th Nov 2016, 3:09 AM
R2-D2
R2-D2 - avatar
+ 2
Yes the answer is correct, it called diamond problem. In c++ it is solved by using virtual methods, but nowadays, the languages avoid this problem by just restricting the number of classes that can be inherited i.e. restricting to only 1 class.
1st Dec 2016, 1:28 AM
Akshay Khandizod
Akshay Khandizod - avatar