请直接看我精简后的代码:
public class HomeTest {
private String home = "This is HOME";
public void printHome() {
System.out.println(home);
}
}
public class SmallHomeTest extends HomeTest {
private String home = "This is SMALL HOME";
}
public class Entry {
public static void main(String[] args) {
SmallHomeTest small = new SmallHomeTest();
small.printHome();
}
}
这里的运行结果是This is HOME,而不是"This is SMALL HOME",也就是说,子类HomeTest调用的继承来的方法printHome()里使用的属性,是父类里的private Home,这点我很奇怪,父类里的private不应该是对子类屏蔽的吗?求解释,谢谢!
莫回无
慕桂英4014372
小唯快跑啊
慕无忌1623718
BIG阳
相关分类