Java 中的 Top-most class 是什么?
What is a Top-most class in Java?
因此,主要问题是了解 Java 的 class 层次结构。
我们需要回答这个问题:
"Explain whether in Java there is one single class hierarchy (with a single class at the top) or there are many class hierarchies (each with its own top-most class). Explain what consequences this has."
我不知道如何回答这个问题..
来自 Object
JavaDoc:
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.
编辑: 另请参阅 the spec。
java 中的所有对象都继承自 Object
它是Object class。
The class Object is a superclass (§8.1.4) of all other classes.
还要检查这个 Oracle docs:
The Object class, in the java.lang package, sits at the top of the
class hierarchy tree. Every class is a descendant, direct or indirect,
of the Object class. Every class you use or write inherits the
instance methods of Object.
Object
class 是所有 java class 之母。
您可以通过编程方式进行验证。
对于 Object
的 Super Class
,您将在下面的代码中得到 null
Object.class.getSuperclass(); // returns null
以上测试可以对任何其他 class 类似地进行。
是对象Class。每个 class 都是 java.lang 包中对象 class 的直接或间接后代。与任何其他 parent/child class 不同,它不需要扩展关键字来继承。它本质上是隐式的,您可以在其中显式编写。 Java编译器不否认。
您可以从任何其他 class use/call 对象 class 的方法,同时您可以覆盖它们以按照您的方式实现。
因此,主要问题是了解 Java 的 class 层次结构。 我们需要回答这个问题: "Explain whether in Java there is one single class hierarchy (with a single class at the top) or there are many class hierarchies (each with its own top-most class). Explain what consequences this has."
我不知道如何回答这个问题..
来自 Object
JavaDoc:
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.
编辑: 另请参阅 the spec。
java 中的所有对象都继承自 Object
它是Object class。
The class Object is a superclass (§8.1.4) of all other classes.
还要检查这个 Oracle docs:
The Object class, in the java.lang package, sits at the top of the class hierarchy tree. Every class is a descendant, direct or indirect, of the Object class. Every class you use or write inherits the instance methods of Object.
Object
class 是所有 java class 之母。
您可以通过编程方式进行验证。
对于 Object
Super Class
,您将在下面的代码中得到 null
Object.class.getSuperclass(); // returns null
以上测试可以对任何其他 class 类似地进行。
是对象Class。每个 class 都是 java.lang 包中对象 class 的直接或间接后代。与任何其他 parent/child class 不同,它不需要扩展关键字来继承。它本质上是隐式的,您可以在其中显式编写。 Java编译器不否认。
您可以从任何其他 class use/call 对象 class 的方法,同时您可以覆盖它们以按照您的方式实现。