计算机二级java辅导:构造方法的继承

2014-11-20 00:20:14 · 作者: · 浏览: 21

  构造方法是一种特殊的方法,它的继承规则比较简单,而且与普通方法有较大的区别


  1 无参数构造方法的构造方法示例


  class hasConstructor{


  protected int x=100;


  public void showMsg(){


  System.out.println("this is a method in ancesstor");


  }


  public hasConstructor(){


  System.out.println("this is a constructor in ancestor without parameter");


  }


  public hasConstructor(int ix){


  System.out.println("this is a constructor in ancestor with parameter");


  }


  }