// Fig. 3.7: GradeBook.java
// GradeBook class that contains a courseName instance variable
// and methods to set and get its value.
// U3 P.103
public class GradeBook
{ ↓實體變數
private String courseName; // course name for this GradeBook
//method to set the course name
public void setCourseName ( String name )
{ ↑用來設定屬性courseName內容值的set方法
courseName = name; // store the course name
} // end method setCourseName
// method to retrieve the course name
public String getCourseName ()
{ ↑用來提領屬性courseName內容值的get方法
return courseName;
} // end method getCourseName
// display a welcome message to the GradBook user
public void displayMessage()
{
// this statement calls getCourseName to get the
// name of the course this GradeBook represents
System.out.printf ("Welcome to the grade book for \n%s!\n",getCourseName() );
} // end method displaymessage ↑呼叫get的方法
} // end class GradeBook
圖3.7 包含了一個 courseName 實體變數的 GradeBook 類別
java.GradeBook
出現:Exception in thread "main" java.lang.NoSuchMethodError: main
留言列表