tags:

views:

89

answers:

4

We know that in java all classes extends Object. but Object itself is a class in java. so is this class also extends by itself or any other class?

+6  A: 

No, java.lang.Object doesn't extend anything. If you ask Object.class for its superclass, it will return null.

It would be more accurate to say that every class except Object inherits directly or indirectly from Object. The wording of the Java Language Specification says:

Each class except Object is an extension of (that is, a subclass of) a single existing class (§8.1.4) and may implement interfaces (§8.1.5).

and also:

The extends clause must not appear in the definition of the class Object, because it is the primordial class and has no direct superclass.

Jon Skeet
A: 

Object is referred to as the top Java class. It’s at the TOP, so nothing above it... except native code.

dpb
There is nothing "above" Object ... not even native code.
Stephen C
@ Stephen C: How about all those "native" methods?
dpb
Many of the methods of Object are declared as `native`, but methods of other classes are also declared as `native`. It doesn't mean there is anything "above" Object in the class heirarchy.
Stephen C
The JVM is at the top... but that’s not a class. 10-4 Stephen C!
dpb
+1  A: 

Object is the root of the Java class hierarchy. It therefore does not extend any other class.

http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html

mmccomb
+1  A: 

Well, java.lang.Object is the root class in class hierarchy. All other classes by default extend the Object class. The Object provide default implementations for many important methods like equals(), hashcode(), toString(), which all other Objects can either user or override them as per their requirement. Since Object is in java.lang package, it is imported implicitly because java.lang package is imported implicitly. Hope this helps you mate.

Nitin Ware