演示后期绑定的结果。
class MyClass extends MyBase{ public void print() { System.out.println("Inside MyClass.print()");/* 来自 nowjava - 时 代 Java*/ } } class MyBase { public void print() { System.out.println("Inside MyBase.print()"); } } public class Main { public static void main(String[] args) { MyBase lbSuper = new MyBase(); MyClass lbSub = new MyClass(); /** nowjava - 时代Java 提供 **/ // Will access MyBase.print() lbSuper.print(); // #1 // Will access MyClass.print() lbSub.print(); // #2 // Will access MyClass.print() ((MyBase)lbSub).print(); // #3