开发者

subclass inheritance with different packages?

Thanks for the great answers about inheritance. Just one more quick question:

A subclass can always inherit the protected members of its superclass. Is that true even if they are not in t开发者_如何学Gohe same package?


Yes, they can always inherit the protected members of its superclass regardless of the package they are in.

From the 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.

From the 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.

I think, this may be your required solution


Subclasses in Java have access to protected members of all superclasses, regardless of the package relationship.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜