问题
Why object Class is a super class in java yesterday i had one interview and the interviewer asked me the questions.
回答1:
Because the Object class, in the java.lang package, sits at the top of the class hierarchy tree.
回答2:
Because it is just a definition. Actually sec 4.3.2 of jls8 said:
The class Object is a superclass (§8.1.4) of all other classes.
There is no more formal way to define Object class.
回答3:
Because all objects in Java inherited from Object class.
So if you create your class for example MyObject, parent for this object will be Object class.
It's mean that Object is super class for class MyObject.
回答4:
All classes in Java by default "extend" the Object class, that's why Object is superclass of every class in Java.
As per the definition of class "Object".
Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
A similar question which was discussed before ... Default class that is extended by all classes in java
来源:https://stackoverflow.com/questions/24094020/why-object-class-is-superclass-in-java