日期:2014-05-20 浏览次数:20875 次
class ParentClass { public String AAA = "111"; public void say(){ System.out.println(AAA); } } class SubClass { public String AAA = "777"; } class TestClass { public void main(){ SubClass sub = new SubClass(); sub.say(); } }
class ParentClass { private String AAA = "111"; public void setAAA(String s){ AAA = s; } public void say(){ System.out.println(AAA); } } class SubClass extends ParentClass { } class TestClass { public static void main(final String[] args){ SubClass sub = new SubClass(); sub.setAAA("777"); sub.say(); } }
------解决方案--------------------
这个因为是通过父类方法say去访问被覆盖的属性的话不会动态绑定的
------解决方案--------------------
只有方法才有重写一说,变量没有