[英]How can a class, extending another class, extends Object class though multiple inheritance is not allowed?
Since I am new to java. 因为我是java的新手。 I want to know if multiple ineritance is not supported in java then how a class extends another class alongwith the default superclass Object? 我想知道java中是否不支持多个ineritance,那么类如何扩展另一个类以及默认的超类Object?
因为虽然不允许多重继承,但是一个类可以从另一个继承另一个类 - 并且最终该链顶部的类将继承自object(如果你没有指定任何特定的类,它会这样做)它继承自。)
Although this is already answered, here is a diferent perspective. 虽然已经回答了这个问题,但这是一个不同的观点。 Try to think of it in human terms. 试着用人的角度来思考它。 You can't have 2 biological fathers, but you inherit the traits from your father, your grandfather, great grandfather and so on... In the same way, when you extend a class, that class becomes the parent class and you'll inherit traits from every parent class up the tree. 你不能拥有2个亲生父亲,但是你继承了父亲,祖父,曾祖父等人的特征......同样地,当你扩展一个班级时,那个班级就成了父班,你就会从树上的每个父类继承特征。
;) ;)
There are two similar sounding concepts related to inheritance Multiple Inheritance and Multi-Level Inheritance. 有两个类似的声音概念与继承多重继承和多级继承有关。
Multiple Inheritance is not allowed in java. java中不允许多重继承。 This stops a class from inheriting multiple classes. 这会阻止类继承多个类。 For example we can't declare a class as: 例如,我们不能将类声明为:
Class C extends A, C
But as multilevel inheritance is allowed, extending of class B, which extends class A, by class C is allowed. 但是,由于允许多级继承,因此允许通过类C扩展类A(扩展类A)。 So class hierarchies like 所以类层次结构就像
Class B extends A
and 和
Class C extends B
is allowed. 被允许。
"Multiple inheritance" is different than what you describe - it refers to a single class extending more than one class, such as “多重继承”与您描述的不同 - 它指的是扩展多个类的单个类,例如
public class MultipleClass extends ClassA, ClassB 公共类MultipleClass扩展了ClassA,ClassB
What you have described is just a hierarchy of inheritance. 你所描述的只是一种继承的层次结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.