In java how every class is inheriting from Object class without using extends keyword? How can we implement our on java class in the same way?
Asked
Active
Viewed 42 times
0
-
1Its like that because of a specification. No, you cant implement your own class – XtremeBaumer Feb 26 '19 at 11:35
-
The compiler fills in "extends java.lang.Object` when there is no `extends`. It is written in the .class file. Only the class Object has no super class. – Joop Eggen Feb 26 '19 at 11:37
-
you should implement your own compiler! – Mosius Feb 26 '19 at 11:38
1 Answers
1
In java how every class is inheriting from Object class without using extends keyword?
By fiat. That is, because the spec says so, in a couple of places (for instance, here). Probably the clearest is §8.1.3:
Given a (possibly generic) class declaration C<F1,...,Fn> (n ≥ 0, C ≠ Object), the direct superclass of the class type C<F1,...,Fn> is the type given in the extends clause of the declaration of C if an extends clause is present, or Object otherwise.
Continuing with your question:
How can we implement our on java class in the same way?
You can't.

T.J. Crowder
- 1,031,962
- 187
- 1,923
- 1,875