Why multiple inheritance is not supported in Java


In Java, a class cannot extend more than one class. Therefore following is illegal −

Example

public class extends Animal, Mammal{}

However, a class can implement one or more interfaces, which has helped Java get rid of the impossibility of multiple inheritances.

The reason behind this is to prevent ambiguity.

Consider a case where class B extends class A and Class C and both class A and C have the same method display().

Now java compiler cannot decide, which display method it should inherit. To prevent such situation, multiple inheritances is not allowed in java.

Updated on: 07-Sep-2023

36K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements