中級 › non-static variable cannot be referenced の原因と直し方 › パターン3
non-static variable cannot be referenced の原因と直し方
staticとインスタンスの境界。
1 public class Main { 2 _______ int LIMIT = 100; ^ 3 4 public static void main(String[] args) { 5 System.out.println(LIMIT); 6 } 7 }
Main.java:5: error: non-static variable LIMIT cannot be referenced from a static context
空欄を埋めてビルドを通す
staticなmainから直接使いたい変数はstaticにします。定数は static final にするのが慣習です。
次の問題