• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Polymorphism

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why java doesn't support multiple inheritance?
I know indirectly it can be achieved through Interface.
Thanks,
senthil
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is one of the most confusing, problem-causing things in other languages, so the creator of Java decided to not use it.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic