今天看到java中子类能不能继承父类的私有成员,于是验证了一下.
</pre><pre name="code" class="html"><pre name="code" class="java">class People{
private int i = 10;
public int getI(){
return i;
}
}
class Student extends People{
public static void main(String[] a){
Student s = new Student();
s.getI(); //不报错
// s.i(); //报错
}
}
结果没有问题.
结论java中子类能不能继承父类的私有成员.因为如果继承就有s.i,只是Student继承了geiI()方法.