aspose file tools*
The moose likes Beginning Java and the fly likes multiple inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "multiple inheritance" Watch "multiple inheritance" New topic
Author

multiple inheritance

singh rajiv
Greenhorn

Joined: Jan 27, 2010
Posts: 1
why java does not support multiple class inheritance. as c++ support.

help!!!
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Is that a question ?
welcome to javaranch singh rajiv


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 02, 2003
Posts: 11229
    
  16

From what i've read, the designers thought that the headaches caused by multiple inheritance vastly outweighed any benefits gained by including it.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

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


http://www.lifesbizzare.blogspot.com || OCJP:81%
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
It's not supposed to have anything to do with variables, but with methods.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 17, 2010
Posts: 65
The diamond problem still exists with interfaces.....then why was multiple inheritence removed...was there any technical reason?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
 
subject: multiple inheritance