Code Fix

中級non-static variable cannot be referenced の原因と直し方 › パターン1

non-static variable cannot be referenced の原因と直し方

staticとインスタンスの境界。

 1  public class Main {
 2      int count = 10;
 3  
 4      public static void main(String[] args) {
 5          System.out.println(________________);
                                       ^
 6      }
 7  }
Main.java:5: error: non-static variable count cannot be referenced from a static context

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

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

non-static variable cannot be referenced の原因と直し方

mainから他のメンバーを呼ぶときの3つの選択肢を比較します。

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

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