これについて議論したいのですが、私の場合の答えを推測できませんでした。まだ助けが必要です。
これが私のコードです:
package JustRandomPackage;
public class YetAnotherClass{
protected int variable = 5;
}
package FirstChapter;
import JustRandomPackage.*;
public class ATypeNameProgram extends YetAnotherClass{
public static void main(String[] args) {
YetAnotherClass bill = new YetAnotherClass();
System.out.println(bill.variable); // error: YetAnotherClass.variable is not visible
}
}
上記の例は紛らわしいようです。
1. Subclass is a class that extends another class.
2. Class members declared as protected can be accessed from
the classes in the same package as well as classes in other packages
that are subclasses of the declaring class.
質問:int variable = 5
サブクラスYetAnotherClass
インスタンス (bill
オブジェクト)からプロテクト メンバー ( ) にアクセスできないのはなぜですか?