所有类如何从Object继承? [英] How do all classes inherit from Object?

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

问题描述

所有类都继承自 java.lang.Object ,虽然 extends Object 。如果你没有明确写 extends Object ,那么这是怎么回事?

All classes inherit from java.lang.Object, although extends Object is (generally) not written out anywhere. How is this possible?

推荐答案

c>编译器为您做。因此,知道一个类只能扩展一个超类,编译器将查看层次结构并将最高的超类扩展到 Object 。因此每个类都将直接或间接继承 Object 类。

if you don't explicitly write extends Object the compiler does it for you. So knowing that a class can only extend one super class, the compiler will look at the hierarchy and extend the highest super class to Object. So every class will directly or indirectly inherit the Object class.

code> class是一种特殊情况,因为它不扩展任何东西。

The Object class however is a special case because it doesn't extend anything.

最后,如果你编译一个简单的类并反编译,编译器插入将
java.lang.Object (或
等效的字节代码)
扩展到类

Lastly if you were to compile a simple class and decompile it, you will see the compiler inserts extends java.lang.Object (or the bytecode equivalent) into the class

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

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