为什么构造函数不被继承? [英] Why Constructors are not inherited?
问题描述
我一直在使用Eclipse Juno学习继承中的构造函数。
I have been learning constructors in Inheritance using Eclipse Juno.
当我在ctrl + O中两次执行childClass时,它显示继承的成员。
但是我偶然看到继承成员的超类的构造方法
When I press ctrl+O twice in the childClass, It shows inherited members. But I happen to see even the Constructor of super class in the inherited members
但是据说构造函数不被继承...
But it is said that constructors are not inherited...
有人可以解释这个行为吗?
Can someone please explain this behaviour?
推荐答案
与字段,方法和嵌套不同类,构造函数不是类成员。
Unlike fields, methods, and nested classes ,Constructors are not class members.
子类继承所有成员(字段,方法和嵌套类)从其超类。构造函数不是成员,所以它们不被子类继承,但可以从子类调用超类的构造函数。
A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.
这篇关于为什么构造函数不被继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!