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

Polymorphism

SenthilNathan CAlagan
Greenhorn

Joined: Jun 21, 2001
Posts: 4
Why java doesn't support multiple inheritance?
I know indirectly it can be achieved through Interface.
Thanks,
senthil
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
It is one of the most confusing, problem-causing things in other languages, so the creator of Java decided to not use it.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Randall W. Smith
Greenhorn

Joined: Jul 28, 2001
Posts: 9
Originally posted by SenthilNathan CAlagan:
Why java doesn't support multiple inheritance?
I know indirectly it can be achieved through Interface.
Thanks,
senthil

I'm hardly the one to answer this as I am truly a newbie but I just heard comments on this very subject while listening to Bruce Eckel's Thinking in Java CD. It's chapter 8 slide 4 in case you have it.
It's not allowed because of the problem you run into while upcasting in C++. If you have an object x and object A and B both inherit from x, both A and B have a "sub-object" of x. If you upcast from A to x your asking for the address of the sub-object in A.
Now if you have an object C that inherits from A(with its sub object x) and B (with it's sub object x) you now have two sub objects in C both with their own separate references to x. Here's where the problem comes in, if you then try to upcast to X from C... which sub object do you use? That will cause ambiguity errors. That's what happens in C++. Java takes the "interface/implements" approach to avoid such problems.
What I don't understand is the use for even Java's version of multiple inheritance. I'm still struggling with that chapter of the TIJ book.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism