本帖最后由 duanyoujiji 于 2014-4-10 08:22 编辑
A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass.
官方是这么说的,一个子类是不能继承父类的私有成员,然而,如果父类有公开访问和受保护权限修饰符私有字段的方法,那么这些方法会被子类继承。 给你链接 http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
这就是父类私有字段要设置访问方法 public xxx getXxx ();void setXxx();不要想得那么复杂,访问权限控制修饰符明白就行。
还有一句 A subclass inherits all of the public and protected members of its parent。不是所有,只是public和protect修饰的成员才被继承。
|