Newsletter Subscription

Jobboard

How would you implement multiple inheritance in Java?

Multiple inheritance is the ability of a single class to inherit from multiple classes. Java does not have this capability.

The designers of Java considered multiple inheritance to be too complex, and not in line with the goal of keeping Java simple.

Multiple inheritance can cause the diamond problem

One specific problem that Java avoids by not having multiple inheritance is called the diamond problem. You can read more about that problem here: Java diamond problem.

Java’s alternative to multiple inheritance – interfaces

What a Java class does have is the ability to implement multiple interfaces – which is considered a reasonable substitute for multiple inheritance, but without the added complexity. This is what a Java class that implements multiple interfaces would look like: