public class Person {
String name;
int weight;
int height;
public Person(String name, int weight, int height){
this.name=name;
this.weight=weight;
this.height=height;
}
public Person(String name, int weight){
this(name, weight);
}
}
エラー:(12、12)Java:再帰コンストラクター呼び出し
エラーなしでコンパイルするには何を変更すればよいですか?
IntelliJ 2017.1の使用
public Person(String name, int weight){
this(name, weight);
}
はい。それは再帰的です。同じコンストラクタを呼び出す。
たぶん相手に電話したい
public Person(String name, int weight){
this(name, weight,0); // default height 0
}
this(name, weight,0);
0
利用可能な高さがないので、3つのパラメーターと高さを渡して他のコンストラクターを呼び出します。または、デフォルトの高さを渡すことができます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加