[英]Calling a subclass constructor with a variable affecting the super constructor
[英]Calling the super constructor in a subclass?
你如何調用子類中的超類構造函數來使這段代碼工作?
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);
}
}
你可以像這樣調用超級構造函數,
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.