对象类作为Java中的超类 [英] Object class as super class in Java

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

问题描述

为什么对象类是Java中的超类?

Why is object class the super class in Java?

推荐答案

这是一个很好的问题。 Java选择让一个类作为一切的父类,所以有一个简单的方法传递任何任意对象,而不需要知道它的类型(即你可以使用声明类型的对象来引用每个单个项目在类型系统中,甚至使用它们的包装类的基元)。但是,有一些OOP语言,例如C ++,其中没有像Java中那样的通用基类。拥有通用基类的另一个好处是,处理超类的逻辑不必为顶级类(除了通用基类,Object本身之外)特殊使用。

That is a good question. Java chose to make a single class be the ultimate parent class for everything so that there is an easy way to pass around any arbitrary object, without needing to know its type (i.e. you can use the declared type of Object to refer to every single item in the type system, even primitives using their wrapper classes). However, there are OOP languages such as C++ where there is no universal base class as in Java. Another benefit to having a universal base class is that logic dealing with the superclass does not have to be special cased for top-level classes (with the exception of the universal base class, Object, itself).

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

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