私はプログラミングの初心者です(そしてJava)、基本的な概念についていくつかの助けをすることができます。 これは私のコンストラクタ、setとget文に関する読者のサンプルです。Javaクラスはどのように入力を取得しますか?
1 // Fig. 3.10: GradeBook.java
2 // GradeBook class with a constructor to initialize the course name.
3
4 public class GradeBook
5 {
6 private String courseName; // course name for this GradeBook
7
8 // constructor initializes courseName with String supplied as argument
9 public GradeBook(String name)
10 {
11 courseName = name; // initializes courseName
12 }
13
14 // method to set the course name
15 public void setCourseName(String name)
16 {
17 courseName = name; // store the course name
18 } // end method setCourseName
19
20 // method to retrieve the course name
21 public String getCourseName()
22 {
23 return courseName;
24 } // end method getCourseName
25
26 // display a welcome message to the GradeBook user
27 public void displayMessage()
28 {
29 // this statement calls getCourseName to get the
30 // name of the course this GradeBook represents
31 System.out.printf("Welcome to the grade book for\n%s!\n",
32 getCourseName());
33 } // end method displayMessage
34
35 } // end class GradeBook
私は、セットとゲットの間のステップを理解するのが少し難しいです。私の本は何も説明していませんでしたが、ユーザーがデータを入力するように促す方法はありますか?これらのいずれかのプロンプトはデフォルトで入力されていますか?私が理解できるのは、メソッドsetCourseName(String name)はコース名が文字列でなければならないということです。しかし、私はcourseName = nameのインスタンス変数を理解していません。またはgetCourseNameメソッドの機能この例を理解できるように助けてくれますか?