第六次上课博文

1.用super()方法调用父类中被覆盖的的方法

package test;

 

class Father

{

  protected int num;

  public void  numAddOne()

  {

     System.out.println("父类的方法输出结果为 "+Integer.valueOf(num+1)) ;

  }

}

 

class Son1 extends Father

{

  public void numAddOne()

  {

     super.numAddOne();

     System.out.println("子类的方法输出结果为 "+Integer.valueOf(num+2)) ;

  }

}

 

public class TestSuper

{

  public static void main(String args[])

  {

     Son1 son = new Son1();

     son.numAddOne();

  }

}

 

原文地址:https://www.cnblogs.com/1102whw/p/4941893.html