Thursday, July 23, 2015

JAVA does not support multiple Inheritance

Why JAVA does not support multiple Inheritance ?

JAVA removes rarely used and confusing features from C++.

Multiple Inheritance gives rise to the common diamond problem.

 
 
In the above figure we have two classes B and C inheriting from A.

Assume that B and C are overriding an inherited method and they provide their own implementation.

Now D inherits from both B and C through multiple inheritance and thus D should inherit that overridden method.

Which overridden method will be used? Will it be from B or C?

This gives rise to ambiguity.

Hence it was felt better to remove this feature from JAVA.

If required this feature can be substituted by alternative design by using interfaces in JAVA.
 

No comments:

Post a Comment

Home