this: 最终子类的地址
super:每一层的父类
所以不管每一层的this都是指向最下层子类,如果找不到方法就去上找,直到找到方法
public class Test {
public static void main(String[] args) {
Animal a = new Dog();
a.shout();
}
}
public class Animal {
public void shout() {
System.out.println("shout……!");
eat();
}
public void eat() {
System.out.println("eat……!");
}
}
public class Dog extends Animal {
public void eat() {
System.out.println("狗粮真香啊……!");
}
}
运行这个理解程序就会有所理解