gpt4 book ai didi

java - 不同包的子类继承?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:33:29 27 4
gpt4 key购买 nike

感谢您提供有关继承的出色答案。还有一个简单的问题:

子类总是可以继承其父类(super class)的 protected 成员。即使它们不在同一个包中也是如此吗?

最佳答案

是的,它们总是可以继承其父类(super class)的 protected 成员不管它们所在的包。

来自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

关于java - 不同包的子类继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6543499/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com