This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

multiple inheritance  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why java does not support multiple class inheritance. as c++ support.

help!!!
 
Bartender
Posts: 1979
57
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that a question ?
welcome to javaranch singh rajiv

 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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: 1979
57
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • 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
  • 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: 12628
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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: 61753
193
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!