第六次上课博文

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

  }

}

 

 

posted @ 2015-11-06 10:39  学计算机的人绝不认输  阅读(121)  评论(0编辑  收藏  举报