Java and single inheritance

Started by
251 comments, last by zacharya 20 years, 1 month ago
I just want to know why Java doesn''t support multiple inheritance.... Everybody told me that Java''s OOP concept is better than C++ but what makes me curious is why in Java I can''t do multiple inheritance like in C++.
being young is a treasure that can''t be valued
Advertisement
It is impossible to have multiple inheritance in JAVA with concrete class (only with interface).
Because it''s very hard to implement, and almost impossible to implement correctly(just look at what a mess it is in C++. People say Eiffel got it right, though).

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:Original post by zacharya
Everybody told me that Java''s OOP concept is better than C++ but what makes me curious is why in Java I can''t do multiple inheritance like in C++.
Choice by the language designers. Specifically, a reaction to a common problem in C++.

In C++, multiple inheritance can often lead to the "diamond inheritance" problem - where a class derived from two classes with a common ancestor consequently receives two (or more) copies of the ancestral class. This is solved with virtual inheritance, but the Java language designers thought it better to attempt to idiot-proof the language by disallowing MI and substituting multiple implementation of interfaces (which can have no data members) instead.

P.S. This lack of respect for my intelligence - repeated often in Java - is one of the reasons I dislike it. Caveat emptor.
quote:Original post by Arild Fines
Because it''s very hard to implement, and almost impossible to implement correctly(just look at what a mess it is in C++. People say Eiffel got it right, though).
I''d like to know your opinions on MI in Python. I find the order of inclusion method interesting, though I''ll readily admit that something about Python makes inheritance less of a critical method - probably the fact that its dynamic typing system and introspective qualities allow for fairly generic programming.
quote:Because it''s very hard to implement, and almost impossible to implement correctly(just look at what a mess it is in C++. People say Eiffel got it right, though).

Eiffelists say that. It''s not clear that they''re right, however. MI does raise certain issues, but it''s probably worth having in spite of these issues.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
quote:Original post by DrPizza
quote:Because it''s very hard to implement, and almost impossible to implement correctly(just look at what a mess it is in C++. People say Eiffel got it right, though).

Eiffelists say that. It''s not clear that they''re right, however. MI does raise certain issues, but it''s probably worth having in spite of these issues.


Yes, it''s worth having because then I have the choice to use it if I want to. Just like operator overloading, pointers, etc. When in the right hands, they are useful tools. When in the wrong hands, they can be dangerous, but those hands are what languages like Java were invented for.



--
Dave Mikesell Software
I''ve never understood the problem people have with multiple inheritance. It is one of the most powerful features in C++ and I don''t think I could program without it. Maybe some little fluffy flowery programs, but I try to avoid those kinds of projects. Sure, you have to keep up with your virtual inheritances, but it isn''t that hard a concept to use. I think people make it harder than it needs to be, cuz it isn''t that hard and can allow you some EXTREMELY powerful code.
quote:Original post by Oluseyi
P.S. This lack of respect for my intelligence - repeated often in Java - is one of the reasons I dislike it. Caveat emptor.


That's an interesting viewpoint. I find it to be a useful separation of interface and implementation. Consider the difference between an interface and an abstract class in Java. In C++, they are one and the same - we create them using pure virtual methods. However, often C++ interfaces have concrete methods implemented. This, IMO, can be a poor design decision in some cases and is often done by those who don't understand the difference. I don't consider Java's version an insult to anyone's intelligence any more than a sophisticated IDE is (when compared to command line development). It was a design decision to aid in reducing common mistakes.

Personally, the only need I have ever for multiple inheritance in C++ is to implement interface-like functionality. I'm sure others may have had a need for inheriting multiple concrete objects, but I have yet to run into such a case myself. At least, not since I learned to think in terms of interfaces. I think there are many cases when people think they need to inherit multiple concrete objects when they really don't.

[edited by - aldacron on February 16, 2004 9:12:33 PM]
quote:Original post by Aldacron
That''s an interesting viewpoint. I find it to be a useful separation of interface and implementation. Consider the difference between an interface and an abstract class in Java. In C++, they are one and the same - we create them using pure virtual methods. However, often C++ interfaces have concrete methods implemented. This, IMO, can be a poor design decision in some cases and is often done by those who don''t understand the difference. I don''t consider Java''s version an insult to anyone''s intelligence any more than a sophisticated IDE is (when compared to command line development). It was a design decision to aid in reducing common mistakes.
An IDE still allows you to drop to command line; the option remains, allowing you to make the choice. IDEs extend the command line, as opposed to hiding it. The analogy is tenuous.

quote:Personally, the only need I have ever for multiple inheritance in C++ is to implement interface-like functionality. I''m sure others may have had a need for inheriting multiple concrete objects, but I have yet to run into such a case myself (emphasis added).
I need say no more.

By the way, I dislike C++ about half as much as I dislike Java.

This topic is closed to new replies.

Advertisement