Java中对象类的继承 [英] Inheritance of Object Class in Java

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

问题描述

当我正在阅读java书籍时,我遇到了每个类扩展了类对象......但是如果想要一个B类来扩展A类......但是B类将是现在有多个继承,一个来自Object类,一个来自Class A.如何解决冲突。
有人可以解释一下吗?

While i was reading java book, i came across "Every class extends class Object"...but if want a class B to extend class A.....but Class B will be now having multiple inheritance,one from Object class and one from Class A.How the conflict is resolved. Can anyone explain?

推荐答案

首先,对象类是每个类的超级/基类/父类,包括用户定义的类。

First of all, Object class is the super/base/parent class of every class including user-defined classes.

所以即使我们没有明确提到它,用户定义的类也是如此默认情况下扩展Object类。

So even if we don't mention it explicitly, the user-defined classes extends Object class by default.

Morevoer,Object类实现一组方法和变量,这些方法和变量对应用程序中创建的所有对象都是通用的。这就是我们将Object类作为所有其他类的基类的主要原因。

Morevoer, Object class implements a set of methods and variables which are common to all the objects being created in the application. This is the main reason why we have Object class as a base class for all the other classes.

例如:

hashCode() - 此方法为在JVM中创建的每个对象创建唯一标识。

hashCode() - this method creates a unique identity for each of the object being created in JVM.

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

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