How multiple inheritance is achieved in java?

Multiple inheritance in Java programming is achieved or implemented using interfaces. Java does not support multiple inheritance using classes.
In simple term, a class can inherit only one class and multiple interfaces in a java programs. In java terminology, we can say that

“A class can extend only one class but it can implement multiple interfaces.”

For example, below inheritance using multiple classes is wrong as two classes cannot be extended or inherited. Class C is inheriting class A and B.

 

Below program example for multiple inheritance is correct as this example is extending only one class A and implementing multiple interface i.e. IB and IC.

 

NOTE: Whenever the question “what is multiple inheritance in java” is asked in an interview, most of the candidates says java does not support multiple inheritance and that’s it. This answer is partially correct and is not a satisfactory answer and we need to state explicitly that java supports multiple inheritance using interfaces not classes.

Here is a complete program example and description for how multiple inheritance is achieved in java using interfaces.

Multiple Inheritance in java – Program example

Here is the complete java program example of multiple inheritance using interfaces. Also, it will extend one class as extending one class in java is allowed.

In this java program, Bird class will extend one class (Color) and use multiple inheritance properties by implementing 2 interfaces i.e. IFlyable and IEatable

Output:
Bird eats
Bird flying
Color Red