Why Object class is Superclass in java [closed]

大城市里の小女人 提交于 2019-12-20 08:04:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!