私はprintThreadを呼び出すと、なぜ0と3を印刷していますか?子クラスメソッドの出力は印刷されませんか?
class Super {
Super() {
three();
}
void three() {
System.out.println("three");
}
}
class Child extends Super {
int three = (int) Math.PI; // That is, 3
void three() {
System.out.println(three);
}
public static void main(String[] args) {
Child t = new Child();
t.three();
}
}
出力に含まは0と3 ですが、それは(Super
であなたの実装が呼び出されることはありません)あなたはこのをステップ実行した場合、three()
は必ず子クラスのメソッドになります3,3
これはどの言語ですか?あなたのコードスニペットはコンパイルされるべきではありません – Lino
あなたは本当のコードを提供する必要があります。 – csmckelvey
私はちょうどコード – shiv