java怎么调用子类中父类被覆盖的方法

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.就可以了。

猜你喜欢

转载自www.cnblogs.com/wushenjiang/p/11749964.html