• 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
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

multiple inheritance

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why java does not support multiple class inheritance. as c++ support.

help!!!
 
Bartender
Posts: 2910
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that a question ?
welcome to javaranch singh rajiv

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because multiple inheritance causes complicated problems such as the diamond problem and because you rarely need multiple inheritance in practice.

The designers of the Java programming language wanted to make a language which was easier to use than C++, so they left out complicated and unnecessary features such as multiple inheritance.

Note that your question is a frequently asked question. Search the forums and you'll find lots of older discussions about why Java does not support multiple inheritance.
 
salvin francis
Bartender
Posts: 2910
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
don't use 31 exclamation marks after a word (especially "help"), it freaks me out !!
I agree with Jesper Young over the complications part,

Imagine java with "virtual functions" !

I hope your next question is not on operator overriding ...

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I like multiple inheritance and miss it. I prefer other implementation patterns, like mixins or traits, but I don't feel as many do that multiple inheritance is inherently evil.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what i've read, the designers thought that the headaches caused by multiple inheritance vastly outweighed any benefits gained by including it.
 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java supports multilevel inheritence that is

one class can extend only one class

i think its made like this just to make it more security conciusnessor just to avoid duplication of variables from different classes or just to avoid errors like duplicate declaration of variables??

Also with the intro of interfaces ,i think its quite a good replacement for multiple inheritence
 
Marshal
Posts: 78659
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not supposed to have anything to do with variables, but with methods.
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:It's not supposed to have anything to do with variables, but with methods.






sir we are accesiing variablle of a class using b's object? doesnt both variables and methods come into play?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Hegde wrote:Also with the intro of interfaces ,i think its quite a good replacement for multiple inheritence


No, it's not; you still have to re-implement behavior. It avoids some pitfalls at the cost of repetition.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The diamond problem still exists with interfaces.....then why was multiple inheritence removed...was there any technical reason?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really.

There's no implementation inheritance, so it doesn't matter which interface you're referring to--you can only implement one method with a given signature. No matter which interface your object is currently acting like it'll call the same implementation--no diamond problem. The diamond problem refers to implementation disambiguation.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic