Why Java Doesn't Support Multiple Inheritance?

The reason why Java does not support multiple inheritance is that when there exist methods with same signature in both the super classes then compiler cannot determine which class method to be called.

When one class extends more than one classes then this is called multiple inheritance. For example, if class C extends class A and B then this type of inheritance is known as multiple inheritance. Multiple inheritance is not supported by Java classes because it creates problems during various operations like casting, constructor chaining etc.

There is one more flavor of multiple inheritance that is called hybrid inheritance. Java does not support that flavor also because it causes diamond problem.

What is diamond problem?

A / \ / \ B C \ / \ / D

Lets say we have two classes and C inheriting from A. Assume that B and C are overriding an inherited method and they provide their own implementation. Now D inherits from both B and C doing multiple inheritance. D should inherit that overridden method, which overridden method will be used? Will it be from B or C? Here we have an ambiguity. This is called the diamond problem.

Hope you have enjoyed reading Why Java Doesn't Support Multiple Inheritance?. Please do write us if you have any suggestion/comment or come across any error on this page. Thank you for reading!



Share this page on WhatsApp

Get Free Tutorials by Email

About the Author

is the founder and main contributor for cs-fundamentals.com. He is a software professional (post graduated from BITS-Pilani) and loves writing technical articles on programming and data structures.