aspose file tools
The moose likes Java in General and the fly likes Multiple Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Multiple Inheritance" Watch "Multiple Inheritance" New topic
Author

Multiple Inheritance

Lambert Stein
Greenhorn

Joined: Oct 30, 2006
Posts: 14
I have not checked to see if a thread exists already that talks about this, but here's my question:
Why did they take out MI from Java? If it's possible in C++, then it's not impossible...
Harjit Singh
Ranch Hand

Joined: Feb 01, 2007
Posts: 77
There never was MI in Java. The way you can implement Mi in java is by interfaces or a class A extending from class B and then extending Class c from A. MI can create lot of issues, even though it is there in C++ doesn't mean its a good thing. If you have to do MI which would mean that you need to really look at your design to see why you would need MI and how you can change that. In the past I was using MI and think it used to be good but later realized how problematic and painful it can get.

- Harjit
Lambert Stein
Greenhorn

Joined: Oct 30, 2006
Posts: 14
Originally posted by Harjit Singh:
MI can create lot of issues, even though it is there in C++ doesn't mean its a good thing.
- Harjit


That's true...
However, just because it is usually bad doesn't mean it shouldn't be supported. If you use it the wrong way, it's your fault, but if you use it the right way, it can really help some programs.
After all, you don't always have the source code, so you can't decide whether something is a class or an interface.
An amphibian, for example, is a SeaCreature and a LandCreature.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

Originally posted by Lambert Stein:

However, just because it is usually bad doesn't mean it shouldn't be supported.


That's an opinion: an arguably valid one, but not one that Java's creators held. Java was designed to be simple, safe, and clear, and MI causes problems with all of these values.


[Jess in Action][AskingGoodQuestions]
Lambert Stein
Greenhorn

Joined: Oct 30, 2006
Posts: 14
But don't interfaces have the same problems, though?
If, for example, to interfaces have the same method, then wouldn't that be just like a problem in MI? Why did they solve that, but not this?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12269
    
    1
As far as I can see your complaint can be reduced to: "Why doesn't Java let me make dumb programming errors that are hard to find."

You should rejoice that the designers were aware of many problems that exist in C++ and designed Java to avoid them.

Bill


Java Resources at www.wbrogden.com
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12928
    
    3

The diamond problem is one of the most well-known issues that make multiple inheritance somewhat ambiguous. In C++, this is solved by introducing virtual inheritance.

You don't have the diamond problem with inheriting multiple interfaces, because you're not inheriting implementation or data from superclasses that way.

My opinion: You don't need multiple inheritance. It's a good thing that the designers of the Java language were conservative. If they would have put in every conceivable feature "just because it's possible" then Java would have been vastly more complex and it would not have been so successful. The more complex a progamming language is, the harder it is to write and maintain progams in it and the less popular it will be.
[ February 16, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Multiple Inheritance
 
Similar Threads
Packet Sniffing
Books on how to win an argument
Abnormal behaviour
is ConcurrentSkipListMap on the exam?
acces denied