Communiquez avec les autres et partagez vos connaissances professionnelles

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

Suivre

Is multiple inheritance possible in java? If yes then how? If no then why?

user-image
Question ajoutée par himanshu mittal
Date de publication: 2013/07/04

multiple inheritance can be achived using multiple interface implementaion in java

No.
Multiple inheritance is not possible in Java.
Implementing multiple interfaces is not inheritance at all.
In inheritance,we get the functionalities whereas by implementing multiple interfaces,we provide the functionalities.

Javed Khan
par Javed Khan , Senior Programmer Analyst , Barclays Technology

Java does support Multiple interface inheritance.
Which means behavior can be inherited from multiple interfaces but one has to provide implementation of that behavior.

No.
There is no support for multiple inheritance in java.
Reason: C++ allows multiple inheritance whereas java completely rejects it.You should look into the Diamond Problem this will help you in understanding the concept.
Diamond Problem: Suppose 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.
Alternate:Multiple Interface Because interfaces specify only what the class is doing, not how it is doing it.
The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can't choose which one to pick.

Multiple inheritance is not possible in java..in multiple inheritance we inherit all the method,member of method and class member of two or more class bt using interface it is not necessary that we achieve multiple interface each and every time.following example demonstrate it as...
interface a { void a(); void b(); } interface b { void c(); void d(); } abstract class InterfaceMultipleInheritence implements a,b { public static void main(String arr[]) { } } explanation ...we can execute it without getting member of a(),b(),c(),d()....

Advaitha Chidurala
par Advaitha Chidurala , Teacher , Little Masters Abacus

Multiple Inheritance i.e..
nothing but extending two parent classes at a time into the child class is not possible in java,but u can achieve such kind of behaviour through interfaces using the "implemets" keyword,which can implent the features of two classes simultaneously.

In java Multiple Inheritance is not possible.It can be posiible by implementing an interfaces

More Questions Like This

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