Java中的多重继承所有类都是从Object类扩展的? [英] Multiple Inheritance in Java since All classes extend from Object class?

查看:97
本文介绍了Java中的多重继承所有类都是从Object类扩展的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题:

如果我声明一个类A - 意味着该类隐式继承自Object Class。

If I declare a class A - means this class in implicitly inheriting from Object Class.

现在如果B类继承自A类

Now If class B inherits from class A

这个B类是否也不是从Object类继承?

is this Class B also not Inheriting from Object class ?

如果是,那是否意味着编写关键字'extends'一些如何覆盖隐式继承(来自Object类)?

If yes, does that mean writing the keyword 'extends' some how override the implicit inheritance ( from class Object) ?

推荐答案

所有类都直接或隐式或明确地从 Object 扩展或间接地,Java中的整个类层次结构最终指向 Object ,它位于根目录。例如,当你写这个:

All classes extend form Object, either implicitly or explicitly, directly or indirectly, the whole class hierarchy in Java ends up pointing at Object, which is at the root. For instance, when you write this:

public class MyClass extends Object {

与此完全相同:

public class MyClass {

如果我们有这个:

public class MySubClass extends MyClass {

然后 MySubClass MyClass 扩展而来,扩展自 Object 。它是一个传递性继承关系,它只在一个方向上发生:在层次结构中没有任何一点,单个类可能从多个类扩展 - 这就是为什么我们说在Java中我们有单继承(相反) to:多重继承。)

Then MySubClass extends from MyClass which extends from Object. It's a transitive inheritance relationship, and it occurs in only one direction: at no point in the hierarchy it will be possible that a single class extends from more than one class - that's why we say that in Java we have single-inheritance (as opposed to: multiple-inheritance.)

这篇关于Java中的多重继承所有类都是从Object类扩展的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆