今、書籍を見ながら勉強しているのですが
public Cleric(String name)を呼び出した時、
中にあるthis()はどのコンストラクタを呼び出すのですか?
最終的にオーバーロードで一番上のコンストラクタが実行され
nameと、そしてMAX_HPとMAX_MPも代入される。
ということであってますか?
public class Cleric {
String name;
int hp = 50;
static final int MAX_HP = 50;
int mp = 50;
static final int MAX_MP = 50;
//コンストラクタ
public Cleric(String name,int hp,int mp){
this.name = name;
this.hp = hp;
this.mp = mp;
}
public Cleric(String name,int hp){
this(name,hp,Cleric.MAX_MP);
}
public Cleric(String name) {
this(name,Cleric.MAX_HP);
}
}
回答3件
あなたの回答
tips
プレビュー