How do all classes inherit from Object?

All classes inherit from java.lang.Object, although extends Object(generally) are not written out anywhere. How is this possible?

+4
source share
2 answers

if you are not explicitly writing extends Object, the compiler does it for you. Therefore, knowing that a class can expand only one superclass, the compiler will look at the hierarchy and extend the highest superclass to Object. Therefore, each class will directly or indirectly inherit the class Object.

A class Object, however, is a special case because it does not extend anything.

, , , java.lang.Object ( -)

+23

Object / .

Oracle Java doc:

: , , ( , ). , , ( ).

, , ( ). - , .

+5

All Articles