Why Java Doesn’t Support Multiple Inheritance

In this tutorial, we are going to see why multiple inheritance is not supported in Java. In Java, a class cannot inherit multiple classes. Therefore, multiple inheritance is prohibited.

Example :
public class A extends B, C { ... }

However, a class can implement one or more interfaces, which makes it possible to replace multiple inheritance.

The reason behind this is to avoid any ambiguity.

Consider a case where class A inherits from class B and class C. Classes B and C have the same show() method.

Now, the Java compiler cannot decide which show() method it should inherit. To avoid ambiguity, multiple inheritance is not supported in Java.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *