Code Fix

上級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

空欄を埋めてビルドを通す

広告
広告スロット(未設定)

super() と this() の呼び出しルール

親に引数なしコンストラクタがない場合の対処を扱います。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)