上級 › super() と this() の呼び出しルール › パターン3
super() と this() の呼び出しルール
必ず先頭に置く必要があります。
1 public class Main { 2 int a, b; 3 Main(int a) { ________(a, 0); } ^ 4 Main(int a, int b) { this.a = a; this.b = b; } 5 public static void main(String[] args) { 6 System.out.println(new Main(1).b); 7 } 8 }
Main.java:3: error: constructor Object in class Object cannot be applied to given types
空欄を埋めてビルドを通す
同じクラスの別のコンストラクタを呼ぶのはthis(...)です。super(...)は親を指します。
次の問題