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

java – 使用不同包的子类继承?

发布时间:2020-12-15 08:41:39 所属栏目:Java 来源:网络整理
导读:感谢关于继承的伟大答案.还有一个问题: 子类总是可以继承其超类的受保护成员.即使它们不在同一个包装中,这是真的吗? 解决方法 是的,他们总是可以继承其超类的受保护成员,而不管它们所在的包. 从 JLS Section 6.6.2 , A protected member or constructor of
感谢关于继承的伟大答案.还有一个问题:

子类总是可以继承其超类的受保护成员.即使它们不在同一个包装中,这是真的吗?

解决方法

是的,他们总是可以继承其超类的受保护成员,而不管它们所在的包.

JLS Section 6.6.2,

A protected member or constructor of
an object may be accessed from outside
the package in which it is declared
only by code that is responsible for
the implementation of that object.

Java Tutorial开始,

The protected modifier specifies that
the member can only be accessed within
its own package (as with
package-private) and,in addition,by
a subclass of its class in another
package.

我想,这可能是你的required solution

(编辑:李大同)

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

    推荐文章
      热点阅读