File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple inheritance

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

help!!!
 
salvin francis
Bartender
Pie
Posts: 1210
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that a question ?
welcome to javaranch singh rajiv

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • 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
Pie
Posts: 1210
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • 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 ...

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • 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.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • 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.
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • 0
  • 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
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • 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: 1077
Java Windows
  • 0
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • 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.
 
Mohnish Khiani
Ranch Hand
Posts: 65
  • 0
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • 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