It is said, that Java language support single inheritance only.
However how is it possible to inherit from Object and from any other class at the same time? Isn’t that a multiple inheritance.
Secondly, what for do we need to inherit all 11 Object methods? I could hardly imagine why do I need it them in I/O e.g.
Finally JDK 8 is going to offer us default methods realization in interfaces and if which would probably cause multiple inheritance in Java.
What if interface A provides method a() with default realization and interface B provides also a() method with another default realization and our custom class C implements both interfaces and rely on default realization – wouldn’t that be Diamond of Death ?
No this is not what happens. Not all classes directly extend from
Objectclass. But only the class at the top level of inheritance hierarchy extends fromObjectclass(implicitly). Rest of the classes lower in the hierarchy, extends from theObjectclass through the super classes. And, this is what we call multi-level inheritance.So, consider the below hierarchy: –
In the above case,
class Ais equivalent toclass A extends Object.I suspect you meant override when you say inherit. You don’t need to override any method of
Objectclass. It’s just on your requirement, whether to override any method or not. For e.g.: – You would often want to overrideequals()method, so as to write custom equality test for your instances. And in that case, you should also override thehashCode()method, to maintain the contract ofequals()andhashCode().I can’t comment on this concept, because I haven’t read about this thing yet. Probably, I would update the answer sometime later.