Theoretically, multiple inheritance is restricted in java but java.lang.Object
class implicitly extended to every class. Need clear explanation about this?

- 645
- 3
- 9
- 16
-
1http://stackoverflow.com/questions/9790435/java-doesnt-support-multiple-inheritance-but-implicitly-every-class-in-java-ext – Ruchira Gayan Ranaweera Jan 21 '15 at 11:57
-
2Multiple inheritance means: one class extends several other classes. That's not allowed in Java. But that doesn't mean that multiple classes can't extend the same class. i.e. a father has many children, but a child has only one father. – JB Nizet Jan 21 '15 at 11:57
-
and that's why interface came. – Md Ashaduzzaman Jan 21 '15 at 11:59
-
1`if (class not extends any class different of Object) then extends Object else extends the other class` – Héctor Jan 21 '15 at 12:01
-
Please anyone explain how to remove duplicate on this question? – Balasubramani Feb 24 '15 at 10:25
6 Answers
Its multilevel inheritance not multiple inheritance.
If your class is not extended by another class then it's extends java.lang.Object
class.
But If your class is extends another class then that another class is not having any super class that class get extend by java.lang.Object
class not your class.
Suppose initially you have class A
class A{
}
It not having any super class so it extends java.lang.Object
class.
But
class B{
}
class A extends B{
}
In this scenario your class is get extends by class B
and B
is not extending another class so at this point B
will extend java.lang.Object
class.
java.lang.Object
class is super class means when your custom super class will end at that time your super class extends java.lang.Object
class.

- 4,873
- 2
- 32
- 50
Not every class directly inherits/extends Object
class.
If a class don't extend any other classes, then it directly extend Object
class in java.

- 31,165
- 11
- 75
- 105
There simply is no multiple inheritance.
All classes inherit either directly from Object
(if no base class is specified) or do so indirectly by virtue of the base class itself inheriting (directly or indirectly) from Object
. All instances only contain a single copy of any fields owned by their parents.
Instead of multiple inheritance, Java relies on Interfaces to allow a class to declare that it offers a set of functionality, and each class may implement
multiple interfaces.

- 334,560
- 70
- 407
- 495
As you stated, in Java, a subclass cannot inherit multiple superclasses (you would use interfaces instead)
However, a superclass can be inherited by multiple subclasses (such as the Object
example)

- 467
- 5
- 16
Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and features from more than one parent object or parent class. Check : Multiple Inheritance - Wiki
Object class : Many classes inherit it; it doesnt inherit from many classes.
You were getting the definition of multiple inheritance mixed up.

- 717
- 1
- 8
- 26
The answer lies in how you see it. As JB Nizet says, it is multi-level inheritance and not multiple inheritance.
Example :
If you look at FileNotFoundException, then it doesn't directly extend Object
. It implicitly gets the properties of Object from its parent's parent's parent i.e, Throwable - which extends Object
So, only the first level parent classes extend Object. The Subclasses of these first level classes extend Object implitly because their parents extend Object.

- 35,966
- 12
- 68
- 104