I read that every class extends a object class by default. Then it should cause multiple inheritance and must not be supported by Java.
When you have something like
class A {}
then A implicitly extends Object. In fact the bytecode resembles
class A extends Object {}
Now, if we have
class B extends A {}
Then B extends A but is also a subclass of Object, since A is a subclass of Object. This is not, however, multiple inheritance:
Object | A | B
Multiple inheritance would look like this:
Object A
\ /
\ /
\ /
B
i.e. B inheriting from two hierarchically unrelated classes.
How can it be multiple inheritance?
class Object { /* stuff */ }
class Foo /* implicit extends Object */ {}
class FooBar extends Foo /* and therefore extends Object */ {}
The rules are described in the Java Language Specification:
The class Object is a superclass (§8.1.4) of all other classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With