What is Multiple Inheritance?
Multiple Inheritance is a feature of an object-oriented concept,
Where a Class can inherit properties of more than one parent class.
_
_____________________________________
Parent1 Parent2
\ /
\ /
Child ____________________________________
What are problem that Occurs in Multiple Inheritance?
The problem occurs when there exist methods with the same signature in both the superclasses and subclass.
On calling the method, the compiler cannot determine which class method to be called and even on calling which class method gets the priority.
NOTE-
Multiple inheritance is not supported by Java using classes, handling the complexity that causes due to multiple inheritances is very complex.
It creates problems during various operations like casting, constructor chaining, etc, and the above all reason is that there are very few scenarios on which we actually need multiple inheritances,
So better to omit it for keeping things simple and straightforward.
How are Multiple Inheritance applied or handled in java by Default Method and Interfaces?
Java 8 supports default methods where interfaces can provide a default implementation of methods.
And a class can implement two or more interfaces.(Basically Multiple Inheritance).
In case both the implemented interfaces contain default methods with the same method signature,
1- The implementing class should explicitly specify which default method is to be used
or
2- It should override the default method.
Comments
Post a Comment