首页 > 其他分享 >在子类中,若要调用父类中被覆盖的方法,可以使用super关键字

在子类中,若要调用父类中被覆盖的方法,可以使用super关键字

时间:2022-11-04 14:25:35浏览次数:43  
标签:Parent show 子类 System Child 父类 super public out

package text;

class Parent
{
    int x;
    public Parent()
    {
        
            System.out.println("Parent Created1");
      }
    public void show(){
        System.out.println("Parent Created2");
    }

}

class Child extends Parent
{
    int y;
    public Child()
     {
    
        System.out.println("Child Created1");

}
    public void show(){
        super.show();
        System.out.println("Parent Created3");
    }

}

public class text
{

public static void main(String args[])
     {

Child c = new Child();
    c.show();
  }

}

 

 

 

标签:Parent,show,子类,System,Child,父类,super,public,out
From: https://www.cnblogs.com/liuxuefeng/p/16857606.html

相关文章