中級 › non-static variable cannot be referenced の原因と直し方 › パターン4
non-static variable cannot be referenced の原因と直し方
staticとインスタンスの境界。
1 public class Main { 2 void run() { System.out.println("running"); } 3 public static void main(String[] args) { 4 ______________(); ^ 5 } 6 }
Main.java:4: error: non-static method run() cannot be referenced from a static context
空欄を埋めてビルドを通す
インスタンスメソッドはstaticから直接呼べません。実体を作ってから呼びます。
次の問題