Hi Guys:-
Why Multiple Inheritance not Supported in Java?
I Need Clear Definition Please Anyone Help me...........................
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi Guys:-
Why Multiple Inheritance not Supported in Java?
I Need Clear Definition Please Anyone Help me...........................
This sub-Forum is titled "What's Wrong With My Code?", meaning there should be questions involving code. Your question is about Java theory, so the sub-forum "Java Theory And Questions" seems more suitable.
Thread moved from Whats wrong with my code
The technical answer would be due to inheritance meaning an "is-a" relationship (you can find a bunch of information regarding this online).
But the practical answer would be simply because multiple inheritance is one of those things which has an extremely rare need, but is extremely common to be abused (refer to some of the multiple inheritance articles for C++). Basically, the idea is that multiple inheritance encourages developers to inherit classes for the purpose of reusing code, instead of the actual purpose of inheritance, which is relationship mapping. Generally speaking, if you find your class needs to inherit more than one object, you should probably consider refactoring.
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
Multiple inheritance has to solve the Diamond Problem.
The safest and easiest solution to this problem while keeping most of the benefits of complete multiple inheritance is to ensure every "class" multiply inherited from has no data members, and no defined methods (a.k.a. contains only abstract methods). This is called an "interface". So what you end up with is the ability for single inheritance and multiple interfaces, a reduced form of multiple inheritance.
Java's design reasoning is that this pattern solves the vast majority of problems while avoiding the Diamond Problem, and calls it a day. So yes, you are crippled in what you can do, but it's probably for your own good (this is the reason for quite a few features of the Java language).