public class b { { void show() { System.out.println("b"); } } public class c extends b { void show() { System.out.println("c"); } void showc() { super.show(); show(); } } public static void main(String[] args) { c x=new c(); x.showc(); } }
運行結果:
可以看到,要調用子類中與父類同名的方法,要加一個super.就可以了。