Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Why is multiple inheritance not supported in java?

user-image
Question ajoutée par Amit Jain , System Engineer , Capgemini Service India Limited
Date de publication: 2017/06/22
Mohd Faisal
par Mohd Faisal , Sr. Mobile Application Developer(Android/iOS/Flutter) , Naqel Express

There is no support for multiple inheritance in java.Multiple inheritance is where we inherit the properties and behavior of multiple classes to a single class. C++, Common Lisp, are some popular languages that support multiple inheritance.

JAVA Definition: A simple, object oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high performance, multi threaded, dynamic language.

 

Now keep simple in your mind .In order to enforce simplicity should be the main reason for omitting multiple inheritance. For instance, we can consider diamond problem of multiple inheritance.

We have two classes B 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.

In C++ there is a possibility to get into this trap though it provides alternates to solve this. In java this can never occur as there is no multiple inheritance. Here even if two interfaces are going to have same method, the implementing class will have only one method and that too will be done by the implementer. Dynamic loading of classes makes the implementation of multiple inheritance difficult.

 

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?