Among object-oriented languages, one feature that varies considerably is whether the language allows multiple inheritance. C++ does but Ada does not. Java takes a middle ground approach of allowing multiple inheritance of interfaces but not classes. Using a C++ example, illustrate some of the complexities that multiple inheritance introduces. How does C++ deal with them? Why does Java's middle ground approach offer some of the benefits of multiple inheritance while avoids its problems.

Respuesta :

Multiple inheritance causes Diamond problem which happens when:

Class A is parent of class B and C

Now when class D will be inherited from both Class B and C it will have all the members of class A and B which if same will confuse the compiler to import which one?

C++ solves it by using virtual keyword with them and thus telling the compiler which one to inherit.

Java has introduced the interface concept rather then allowing multiple inheritance.