+ 5
Intresting, only c++ alows ineritance from multiply parents... Anybody knows why?
2 Respostas
+ 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.
+ 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.