C++ inhertance

hey,
why in C++ there is multi inheritance while in java there is only inheretance from one object?
what is the assumption that have been made for java?

thanks,
Multiple inheritance opens up a lot of complexities (google or wikipedia for "dreaded diamond" for more info).

Java probably didn't think multiple inheritance was worth the additional complications, so they just removed it from the language.
closed account (zb0S216C)
With multiple inheritance, you run the risk of inheriting a base class twice. For example, say class B and C inherited from the base class A, and class D inherited both class B and C. Class D would have two copies of A's members. This can be avoid by using virtual inheritance, however. Java is safer when compared to C/C++.

Wazzak
In Java you have interfaces, you can multiply inherit from these.

They do not have any data in them so the problem of multiple inheritance creating multiple copies of a base class doesn't arise.
ok thanks, one more question: depends on what u saying I understand that when the inheritance from interface there is no copy made ?
any reference will be helpful.

have a nice day,

A Java interface has only method definitions and constant static data allowed
(so it is like a C++ abstract base class where all the methods are pure virtual)

This means there is no instance specific data at all.

The Java designers put these restrictions in so as to avoid the complexities of multiple inheritance

http://en.wikipedia.org/wiki/Interface_%28Java%29
Topic archived. No new replies allowed.