What type of inheritance is not supported in java, for classes?
i. multilevel inheritance.
ii. multiple inheritance.
iii. hybrid inheritance.
i & ii
ii & iii
i, ii, & iii
Multiple inheritance is not possible in java. Since Hybrid inheritance internally uses multiple inheritance, it is also not supported.
Multilevel inheritance is possible in java.
Java is very popular and easy to code because of its simplicity.
So what ever java developers feel difficult and complicated to understand for programmers, they tried to avoid it. One such kind of property is multiple inheritance.
1. They avoided pointers
2. They avoided multiple inheritance.
Problem with multiple inheritance: Diamond problem.
Assume that class A is having a method fun(). class B and class C derives from class A.
And both the classes B and C, overrides method fun().
Now assume that class D inherits both class B, and C.
Create object for class D.
D d = new D();
and try to access d.fun(); => will it call class B's fun() or class C's fun(). This is the ambiguity existing in diamond problem.
It is not impossible to solve this problem, but it creates more confusion and complexities to the programmer while reading it.
It causes more problem than it tries to solve.
Note: But any way you can always implement multiple inheritance indirectly by using interfaces.
Back To Top