您的位置:首页 > 其它

在子类中调用父类的带参数的构造方法

2015-07-01 17:21 211 查看
public class Beast{

String skin = "";

public Beast(){

}

public Beast(String strSkin){

skin = strSkin;

}

public void move(){

  System.out.println("跑");

}

}

子类Tiger中使用父类的带参数的构造方法

public class Tiger extends Beast{

public Tiger(){

  super("条纹");  //使用父类的带参数的构造方法

}

}

操作被隐藏的成员变量和被重写的成员方法

super.成员变量名//改变父类Beast的成员变量skin的值 super.skin="条纹";

super.成员方法名([参数列表])//调用父类的成员方法move() super.move();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: