始めたばかりなので、困っていることばかりです。
Java本格入門で勉強しています。
StudentSampleクラスを作成して、mainメッソドを定義し、その中でStudentクラスのインスタンスを作成して操作する例をしていたのですが、以下のエラーメッセジが発生しました。
###発生している問題・エラーメッセージ
Exception
1 No enclosing instance of type StudentSanple is accessible. Must qualify the allocation with an enclosing instance of type StudentSanple (e.g. x.new A() where x is an instance of StudentSanple). 2 3 at StudentSanple.main(StudentSanple.java:3)
###該当のソースコード
lang
1public class StudentSanple { 2 public static void main(String...args) { 3 Student murata = new Student(); 4 murata.name = "村田"; 5 murata.score = 80; 6 murata.printScore(); 7 8 Student okada = new Student(); 9 okada.name = "岡田"; 10 okada.score = 90; 11 okada.printScore(); 12 } 13 class Student { 14 String name; 15 int score; 16 static final int MAX_SCORE = 100; 17 18 void printScore() { 19 System.out.println(name + "さんは" + MAX_SCORE + "点満点中、" + score + "点です。"); 20 21 } 22 } 23 }

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/15 14:23