public class SuperClass{ public void printA(){ System.out.print("SuperClass-printA"); printB(); } public void printB(){ System.out.print("SuperClass-p ...
public class SuperClass{ public void printA(){ System.out.print("SuperClass-printA"); printB(); } public void printB(){ System.out.print("SuperClass-printB"); } } public class ChildClass extends SuperClass{ public void printA(){ System.out.print("ChildClass-printA"); super.printA(); } public void printB(){ System.out.print("ChildClass-printB"); } public static void main(String[] args) { ChildClass childClass = new ChildClass(); childClass.printA(); } }View Code
子類通過super.printA()調用父類的方法,而在父類的printA()中調用了printB(),這種情況下,調用的是子類的printB()方法。
相關問題:
http://www.tuicool.com/articles/QBBBfe7