我的家庭作業有這個奇怪的問題。下面有一個類聲明。在與超類構造函數不同的子類中定義構造函數?
public class A {
private String str;
private int num;
public A (String str, int num) {
this.str = str;
this.num = num;
}
現在我需要的是從A類繼承的子類的實現,卻有着不同的構造函數,像這樣:
public class B extends A {
private String str1;
public B (String str, String str1) {...}
// this is where the editor shows an error because class B constructor arguments are
// different from the arguments in the class A constructor
但我需要這種構造是不同的。我怎樣才能做到這一點?
謝謝老兄,我不知道我們可以給super();像這樣的論據(即0),最後一件事情,在超級論據中'0'代表什麼? –
構造函數**不能**被覆蓋。 –
@FabioÇimo0 ist一個int,超級構造函數所需的第二個參數。 –