1. 动态分派
一个体现是重写(override)。下面的代码,运行结果很明显。
1 public class App { 2 3 public static void main(String[] args) { 4 Super object = new Sub(); 5 object.f(); 6 } 7 } 8 9 class Super {10 public void f() {11 System.out.println("super : f()");12 }13 14 public void f(int i) {15 System.out.println("super : f(int)");16 }17 }18 19 class Sub extends Super{20 21 @Override22 public void f() {23 System.out.println("sub : f()");24 }25 26 @Override27 public void f(int i) {28 System.out.println("sub : f(int)");29