Object类允许Java中的多重继承? [英] Multiple Inheritance in Java allowed with Object class?

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

问题描述

在Java中,他们说不支持多重继承。事实上,Java中的每个类都扩展了Object类。所以,如果我写:

In Java, they say that Multiple Inheritance is not supported. Also its a fact, that each class in Java extends class Object. So if I write :

public class ThreadInstance extends Thread {
}

这是如何编译的?这里的ThreadInstance实际上是在扩展Thread和Object。这不是多重继承。

How does this compile? ThreadInstance here is actually extending Thread as well as Object. Isn't it multiple Inheritance here.

推荐答案

通过多重继承,你应该理解同时继承多个类,例如:无法创建

By multiple inheritance you should understand inheriting multiple classes at the same time, e.g. it's impossible to create a

public class ThreadInstance extends Thread, Object {
}

因为类层次结构如下所示:

because class hierarchy would look like this:

ThreadInstance
^            ^
Thread       Object

当你定义 ThreadInstance 就像你一样, ThreadInstance 也继承了 Object ,但是它第一个继承线程。

When you define your ThreadInstance like you did, the ThreadInstance inherits Object too, but it first inherits thread.

ThreadInstance
      ^
    Thread
      ^
    Object

那里没有多重继承。

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

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