###この2つの例が書いてあったが、Eclipseの何らかの機能を使ってこの2つにアクセスさせて解決するのか、2つ合わせて起動させるのかが分かりません。そして、2つを何とか合わせてみたが、エラーが出ました。
java本格入門という本を使っているのですが、入門どころか門前払い寸前です。
Eclipseも入れて3日経ったぐらいの初心者です。
どうか、動くようにするにはどのように改善すればいいでしょうか?
よろしくお願いします。
###発生している問題・エラーメッセージ
Student cannot be resolved to a type Student cannot be resolved to a type Student cannot be resolved to a type Illegal modifier for the local class Student; only abstract or final is permitted at StudentSample.main(StudentSanple.java:3)
###該当のソースコード
lang
1class StudentSample { 2 public static void main(String...args) { 3 Student murata = new Student //村田のインスタンスを作り、名前を設定する 4 5 murata.score = 80; //点数を設定する 6 murata.printScore(); 7 8 Student okada = new Student("岡田",90); //同様に岡田インスタンスを作り名前と点数を設定する。 9 okada.printScore(); 10 } 11}
java
1 class Student{ 2 String name; 3 int score; 4 static final int MAX_SCORE = 100; 5 6 //名前と点数を渡すコンストラクタ 7 Student(String name, int score){ 8 this(name,0); 9 } 10 11 void printSore() { 12 System.out.print(name + "さんは" + MAX_SCORE + "点満点中" + score + "点です。"); 13 } 14 }
###試したこと
2つのコードを入れてみる
java
1public class StudentSample { 2 public static void main(String...args) { 3 Student murata = new Student //村田のインスタンスを作り、名前を設定する 4 5 murata.score = 80; //点数を設定する 6 murata.printScore(); 7 8 Student okada = new Student("岡田",90); //同様に岡田インスタンスを作り名前と点数を設定する。 9 okada.printScore(); 10 11 static class Student{ 12 public String name; 13 public int score; 14 static final int MAX_SCORE = 100; 15 16 //名前と点数を渡すコンストラクタ 17 Student(String name, int score){ 18 this(name,0); 19 } 20 21 void printSore() { 22 System.out.print(name + "さんは" + MAX_SCORE + "点満点中" + score + "点です。"); 23 } 24 } 25 } 26}
回答2件
あなたの回答
tips
プレビュー