加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么构造函数不是继承的?

发布时间:2020-12-15 05:01:39 所属栏目:Java 来源:网络整理
导读:我一直在使用 Eclipse Juno学习继承中的构造函数. 当我在childClass中按两次ctrl O时,它会显示继承的成员. 但我碰巧在继承的成员中甚至看到超类的构造函数 但据说构造函数不是继承的…… 有人可以解释一下这种行为吗? 解决方法 与字段,方法和嵌套类不同,构
我一直在使用 Eclipse Juno学习继承中的构造函数.

当我在childClass中按两次ctrl O时,它会显示继承的成员.
但我碰巧在继承的成员中甚至看到超类的构造函数

但据说构造函数不是继承的……

有人可以解释一下这种行为吗?

解决方法

与字段,方法和嵌套类不同,构造函数不是类成员.

From docs of Inheritance

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.


why constructor removed from class member ??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读