java动态绑定的一点注意
动态绑定只是针对对象的方法,对于属性无效。因为属性不能被重写。
show me code:
public class Father{
public String name = "父亲属性";
}
public class Son extends Father{
public String name = "孩子属性";
public static void main(String[] args){
Father instance = new Son();
System.out.println(instance.name);
}
}
//结果:父亲属性
浙公网安备 33010602011771号