中級 › non-static variable cannot be referenced の原因と直し方 › パターン2
non-static variable cannot be referenced の原因と直し方
staticとインスタンスの境界。
1 public class Main { 2 void greet() { 3 System.out.println("hi"); 4 } 5 public static void main(String[] args) { 6 __________.greet(); ^ 7 } 8 }
Main.java:6: error: non-static variable this cannot be referenced from a static context
空欄を埋めてビルドを通す
staticメソッドの中にthisは存在しません。インスタンスメソッドを呼ぶには実体が要ります。
次の問題