可在子类中访问的私有字段

use*_*983 0 java oop

我有2节课

class A {
   private int count;
}

class B extends A {
   //need to access count here
}
Run Code Online (Sandbox Code Playgroud)

我可以使用哪些标准方法来访问它?

Imr*_*err 7

制作count protected或添加getCount()方法A.

  • 建议`protected`的第一个+1. (2认同)