java 不继承 Object 类的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12684305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:50:02  来源:igfitidea点击:

Classes that don't inherit Object class

javaobject

提问by Arham

Are there any classes that don't inherit Object as SuperClass or maybe have become Obsolete/deprecated?

是否有任何类不继承 Object 作为 SuperClass 或者可能已经过时/不推荐使用?

回答by Ryan Amos

According to Java Object superclass, java.lang.Objectdoes not extend Object.

根据Java Object 超类java.lang.Object不扩展Object

Other than that, all classes, i.e.

除此之外,所有类,即

class ClassName {
    //some stuff
}

implicitly extend Object class, if they don't extend any other super-class.

如果它们不扩展任何其他超类,则隐式扩展 Object 类。

Interfaces, on the other hand, do not extend Object, as Interface, by definition, can not extend Class. Also, Interfaces can not contain callable methods, nor can objects be instantiated from them. When interfaces are finally implemented, the implementing class will necessarily extend Object (and, no, Objectdoesn't implement or extend any other entity/class/interface).

另一方面,接口不扩展对象,因为根据定义,接口不能扩展类。此外,接口不能包含可调用的方法,也不能从它们实例化对象。当接口最终实现时,实现类将必然扩展 Object(并且,不,Object不实现或扩展任何其他实体/类/接口)。

回答by tanyehzheng

According to java.lang.Object javadoc

根据java.lang.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.

类对象是类层次结构的根。每个类都有一个 Object 作为超类。所有对象,包括数组,都实现了这个类的方法。

So, all objects in Java extends it directly or indirectly.

因此,Java 中的所有对象都直接或间接地扩展了它。

回答by Ilia Nedoluzhko

All Java classes inherit java.lang.Object(directly - by default, or via parents). If some class or method become deprecated with some platform release, it is always reflected in appropriate JavaDoc.

所有 Java 类都继承java.lang.Object(直接 - 默认情况下,或通过父类)。如果某个类或方法在某个平台版本中被弃用,它总是会反映在相应的 JavaDoc 中。

回答by user207421

Are there any classes that don't inherit Object as SuperClass

是否有任何不继承 Object 作为 SuperClass 的类

There is exactly one of those, and it is java.lang.Objectitself. Also all interfaces.

正是其中之一,它就是java.lang.Object它本身。也是所有接口。

or maybe have become Obsolete/deprecated?

或者可能已经过时/弃用?

There are plenty of those. See the Javadoc.

有很多。请参阅 Javadoc。