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();

  }

}

 

 第六次上课博文

相关文章:

  • 2021-06-23
  • 2021-07-26
  • 2021-05-28
  • 2022-12-23
猜你喜欢
  • 2021-12-02
  • 2021-09-24
  • 2022-02-13
  • 2022-12-23
  • 2021-12-29
  • 2021-11-18
  • 2021-06-20
相关资源
相似解决方案