Need help with java development

Asked By 0 points N/A Posted on -
qa-featured

hi guys I have a problem regarding to java,is their any way to use multiple inheritance in java,because I need to inherit from two different classes

SHARE
Best Answer by Marienade Mali
Best Answer
Best Answer
Answered By 0 points N/A #94093

Need help with java development

qa-featured

Hello Emerald,

I have read your concern regarding multiple inheritance in Java. As what I have understood, you wanted to know if it’s possible to use multiple inheritance in Java from two different classes. Is it right?

In the first place, java is designed for single inheritance; the creator omitted multiple inheritance per se. Its single inheritance doesn’t usually show a problem; when in fact, multiple inheritance could be a sign of bad design. However, developers found ways to successfully accumulate multiple inheritance in Java and solve the problem. In particular, separately rooted hierarchy with object as the definitive ancestor of all classes and Java solve this issue through C++ in multiple inheritance. Some people think that MI only causes chaos and has very little benefit. Nevertheless, minimal condition shows that multiple inheritance is very useful. It can also be benefited as a refinement of an interface.

I hope I am in the right track of understanding your concern and gave you a hand to fix the problem. I hope this information is of good help.

Good Luck!

Regards,

Mali

Answered By 0 points N/A #195084

Need help with java development

qa-featured

Hello Emerald Hilton,

Java doesn't support Multiple inheritance. It only supports Single and MultiLevel inheritance. Developers intentionally removed this functionality to tackle some problems such as "Diamond Problem of Multiple Inheritance".
 
But, there is another way of achieving Multiple Inheritance, through the use of Interface. A class can implement multiple interfaces.
 
In your case, make sure that all important functions you now defined in the classes are defined in the interfaces and you can implement multiple interfaces to your child class.
 
 
Hope it helps

Login/Register to Answer

Related Questions