Java -- 子类使用super调用父类的方法A,A 调用了方法B,子类也override方法B,那么super.A()最终调用到了子类的B方法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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(); } }
子类通过super.printA()调用父类的方法,而在父类的printA()中调用了printB(),这种情况下,调用的是子类的printB()方法。
相关问题:
http://www.tuicool.com/articles/QBBBfe7