gpt4 book ai didi

java - Java中的多重继承即使类继承了Object

转载 作者:行者123 更新时间:2023-12-02 09:18:29 24 4
gpt4 key购买 nike

Java中的所有类默认都是继承自Object类。

那么继承的类如何可以继承其他类呢?

Java不支持多重继承,对吗?

最佳答案

类继承自至少且最多一个类,

要么隐式地来自 Object(不写 extends),要么显式地来自其他类(extends YourParentClass)

Excepting Object, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object

因为每个类都继承自Object,或者从类继承自Object,所以每个类仍然继承自Object,例如toString()方法

如果您的自定义类继承自不同的类,但仍位于层次结构的末尾,则父类将为 Object,请注意类 hierarchy不是多重继承:

The Object class, defined in the java.lang package, defines and implements behavior common to all classes—including the ones that you write. In the Java platform, many classes derive directly from Object, other classes derive from some of those classes, and so on, forming a hierarchy of classes

At the top of the hierarchy, Object is the most general of all classes. Classes near the bottom of the hierarchy provide more specialized behavior.

关于java - Java中的多重继承即使类继承了Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59455425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com