多重继承和类对象 [英] Multiple Inheritance and class Object
问题描述
我对OOP很新。我们都知道Java不支持多继承;但是,所有Java类都继承自 Object
,并且还可以从另一个类继承。我们可以认为这是多重继承吗? Java如何处理这样的事情?
I am pretty new to OOP. We all know that Java does not support multiple inheritance; however, all Java classes inherit from Object
and can also inherit from another class. Can we consider this as multiple inheritance? How does Java handle such a thing?
推荐答案
这不是多继承,它是多级继承。类可以扩展另一个类,它可以扩展另一个类,...,最终扩展对象:
It's not multiple inheritance it's multi level inheritance. Classes can extend one other class, which can extend one other class, ..., which ultimately extends Object:
A --> B --> C --> Object
多重继承将
A ----> B
\
\--> C
这意味着当在A中使用方法或字段时,然后在B中,然后在C中,然后在Object中。
This means that when a method or a field is used inside A, it's looked up in A, then in B, then in C, then in Object.
使用多重继承,它必须在A中查找,然后在B和C中查找,并且可能存在冲突,因为相同的方法或字段可能存在于两个超类。
With multiple inheritance, it would have to be looked up in A, then in B and C, and there could be a conflict because the same method or field could exist in both superclasses.
这篇关于多重继承和类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!