This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
karthik rsn wrote:can anyone clearly explain me about multiple inheritence.., syntactically it is allowed but conceptually it's not.., so please send in u'r replies..,
Both a class and an interface represents a type. The difference is that a class can carry implementation but an interface cannot.
Now the Java inheritance model supports multiple inheritance of type but only single inheritance of implementation. So Java allows a class to inherit one class at the most but an unlimited number of interfaces. An interface can inherit an unlimited number of interfaces.
In OO design the inheritance of type is considered most important and here Java imposes no restrictions. Java supports multiple inheritance of type.
When it comes to inheritance of implementation Java imposes a restriction. At the most one implementation can be inherited. The reason for this limitation, given in the Java Programming Language by Gosling and others, is problems associated with so called diamond inheritance.
In practice multiple inheritance of implementation, although not supported by Java, can be simulated. This is done by splitting up the class to be inherited into one interface that's inherited and one implementation class that's delegated. The only drawback is that it requires more writing.
So in summary, Java supports multiple inheritance of type, the most important form of inheritance in OO design. Java supports single inheritance of implementation only, but multiple inheritance of implementation can easily be simulated.
is there a technical answer as to why multiple inheritence is removed fron java.....the diamond problem is still possible through interfaces...so why didn't they remove multiple inheritence through interfaces?
Mohnish Khiani wrote:is there a technical answer as to why multiple inheritence is removed fron java.....the diamond problem is still possible through interfaces...so why didn't they remove multiple inheritence through interfaces?
As already answered in the other topic that you bumped -- having the ability to form a diamond doesn't mean that it is a "diamond problem".
And please don't bump multiple topics -- one should be enough.