2

Java does not support multiple inheritance but Object class is by default super class of all classes. e.g

class Object
{

}
class B
{

}
class A extends B
{
}

Class A can access all method of B and Object.Is not it a example of multiple inheritance? So is it correct that Java does not support multiple inheritance.


my question is not to find difference between multilevel and multiple inheritance. Java Docs,it self says :Class Object is the root of the class hierarchy. Every class has Object as a super class. All objects, including arrays, implement the methods of this class. So it means Class Object is super class of Class A{Previous example}. But Class B is also Super Class of Class A. SO what is meaning of it ?

1
  • 2
    +1 Seems like a fair enough question about the meaning of multiple inheritance Commented Sep 26, 2011 at 9:44

4 Answers 4

7

It is know as transitive nature of Inheritance.

Sign up to request clarification or add additional context in comments.

Comments

7

Look at the difference between transitive inheritance (C inherits directly from B and transitively from A):

transitive

and multiple inheritance (C inheriting from both A and B):

transitive

2 Comments

Correct me If I'm wrong. Here in the question Class B has java.lang.Object as its super class while Class A has Class B as its super class. Is the inheritance relationship between Class B and Class java.lang.Object is masked at Class A.
Nope, not masked, everything is just added on, except methods with the same signature, which are overridden. Even variables declared with the same name are added on, they're just said to be "hidden" but can still be accessed using casting, or the super keyword if it's the immediate parent. You wouldn't ever want to do this though, just give your variables different names and they're all added on without any hiding.
4

No it isn't. Multiple inheritance is when a class has more than one direct base class, as in:

class A {}

class B {}

// not valid Java
class C extends A, B {}

A class may have many indirect base classes, each with only one direct base class, as in:

class D extends A {}

class E extends D {}

class F extends E {}

Here the inheritance hierarchy is F -> E -> D -> A -> Object, but this is still single inheritance.

Comments

1

Since no Java class can extend directly two or more classes you can safely say that Java does not support multiple inheritance.

You would have multiple inheritance if you were able to say class A extends B, C, but you can never do that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.