0

hi friends
java does not support multilevel inheritance.
what is the reason behind this??
is this for security reason??

4
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by peter_budo
1

Here are 3 great links that should answer your question:

Some of the reasons being:

1) Multiple inheritances does complicate the design and creates problem during casting, constructor chaining etc thus the reasons for omitting multiple inheritance from the Java language mostly stems from the "simple, object oriented, and familiar" goal.

2) Ambiguity around Diamond problem

Java solution:

Instead, Java's designers chose to allow multiple interface inheritance through the use of interfaces, an idea borrowed from Objective C's protocols. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods.

It is also interesting to note C# also doesnt allow for multiple inheritance of classes and rather multiple interface inheritance.

I guess this is also the reason why Java best practice it to make every class implement an interface, thus you can implement your multiple classes by implementing their interfaces on the new class.

Edited by DavidKroukamp

1

but don't forget, by implementing interfaces you don't really inherit anything, so Java doesn't allow multiple (interface) inheritance through interfaces, it simply allows you to simulate multiple inheritance.

Votes + Comments
thank you for exactness
0

I was really tempted to delete this and another post given the content and user signatures. SEO is always risky poster

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.