看下面这个例子: class SuperClass ... { void method()...{ System.out.println("method() of SuperClass!"); }} // 父类 class SubClass extends SuperClass ... { void method()...{ System.out.println("method() of SubClass"); }} // 子类 public class MainClass ... { public static void main(String[] args)...{ SuperClass a1=new SuperClass(); SubClass b1=new SubClass(); SuperClass a2=new SubClass(); //SubClass b2=new SuperClass(); //编译出错。 a1.method(); b1.method(); a2.method(); //b2.method(); }} 程序输出: method() of SuperClass!method() of SubClassmethod() of SubClass