File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Multiple Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multiple Inheritance" Watch "Multiple Inheritance" New topic
Author

Multiple Inheritance

Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

Why is Multiple implementation inheritence not allowed in Java.
Do we have a logic to put forward ?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Multiple inheritance is not supported because it complicates the compiler
- There may be name collisions of variables and methods of superclasses. Suppose a class C extends Class A and B which has methods show().
- C++ uses explicit referencing of super class methods and attributes but it complicates the complier.


Groovy
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

The name collision can't be ruled out even when implementing multiple interfaces. Like two interfaces defining a varibale with same name.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Java does not have multiple inheritance because it has interfaces. These are two different solutions to the same problem. Java chose interfaces over MI because they are cleaner and more elegant (and used by other Smalltalk-derived OO languages such as Objective-C). This does not mean, however, that they are perfect. You could debate the merits of each back and forth and nobody comes away from the argument feeling happy.
That said, I have yet to come across a situation in my coding where I have actually needed multiple inheritance. And, if I did, I could construct a class that actually uses multiple inheritance. It just takes using interfaces and judicious uses of inner classes. Not that I recommend doing this (and I have not tired this out in practice...), but it is possible.
And, as a note, C# has solved the name-collision problem. This is something that I would like to see included in Java as well.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Inheritance