java - 不同包的子类继承?

标签 java inheritance subclass protected

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

子类总是可以继承其父类(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/

相关文章:

Java 将字节转换为字符 - 转换问题

java - 避免在创建 url 时对数据进行编码

delphi - 当我调用基类上的方法时,如何调用后代的实现?

Java:继承和重写方法问题

java - 引导类路径未与 -source 1.6 3 一起设置

jpa - 使用 Eclipselink/JPA 更改实体类型?

Java - 是否有像 instanceof 这样的 "subclassof"?

java - 如何在 Java 中找到给定类的所有子类?

c++ - 我如何访问一个指针子类方法,那些方法是子类独有的?

java - Apache Camel : creating simple POJO pipelines (put a POJO in and get a POJO out)