Question

Multiple inheritance is not supported in Java (as of yet, but will likely stay this way).

But, what about the Object class? Say you have an object A that inherits from the Object class. Now, you create a class B that inherits from the A class. But, with every class inheriting the Object class, isn't B exhibiting multiple inheritance by both inheriting from Object and A?

Is it that Java knows it will always have objects inheriting from the Object class and therefore can support it easily? Otherwise, if everyone was inheriting from multiple classes all willy-nilly, Oracle would have to have to implement a lot more support.

Or, is it that rather than inheriting from both Object and A, B is inheriting only from A which contains the inheritance from Object all wrapped in one object?

Was it helpful?

Solution

This question is based on a misunderstanding.

But, what about the Object class? Say you have an object A that inherits from the Object class. Now, you create a class B that inherits from the A class. But, with every class inheriting the Object class, isn't B exhibiting multiple inheritance by both inheriting from Object and A?

The misunderstanding is here - "with every class inheriting the Object class"

In fact, an class only (implicitly) extends Object if it does not explicitly extend another class.

Object is the ultimate superclass of every class, but it is not a direct superclass of every class. The Java class hierarchy is a tree, with Object at the top.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top