如何在子类中调用超类构造函数以使此代码起作用?
class Ale {
protected int x = 1;
public Ale( int xx ) {
x = xx;
}
}
class Bud extends Ale {
private int y = 2;
public void display() {
System.out.println("x = " + x + " y = " + y);
}
}
答案 0 :(得分:1)
您可以像这样调用超级构造函数,
class Ale {
protected int x = 1;
public Ale(int xx) {
x = xx;
}
}
class Bud extends Ale {
Bud() {
super(75);
}
private int y = 2;
public void display() {
System.out.println("x = " + x + " y = " + y);
}
}