Reputation: 17651
I have a weird Java question:
As we know:
java.lang.Object
Then, java.lang.Object
must extend java.lang.Object
, which is itself, therefore, it should be impossible. How is Object implemented in Java?
Upvotes: 14
Views: 5512
Reputation: 3096
You'd be better off thinking of this as:
The two main points are: all the classes must implement the implied interface and the Java language spec gives you (forces upon you?) default implementations for these methods for free.
Upvotes: 1
Reputation:
Object does not extend itself. It is the superclass for all other objects in the Java language. Think of it as being the level-0 (or root) class of all the objects in the Java API tree - including any objects you create as well.
I also just want to point out that your question is proven impossible by rule #2 that you posted. Your logic used to justify your question only takes #1 into account and is therefore extremely flawed.
Upvotes: 0
Reputation: 175365
Object
is an exception to the first rule, and has no superclass. From JLS3 8.1.4:
The extends clause must not appear in the definition of the class Object, because it is the primordial class and has no direct superclass.
You can also try it out with reflection:
Object.class.getSuperclass(); // returns null
Upvotes: 20