GradeBook Class with an Instance Variable, a set Method and a get Method
In our next application (Figs. B.5–B.6), class
GradeBook (Fig. B.5) maintains the course name as an instance variable so that it can be used or modified at any time during an application’s execution. The class contains three methods—
setCourseName stores a course name in a
getCourseName obtains a
GradeBook’s course name. Method
displayMessage, which now specifies no parameters, still displays a welcome message that includes the course name; as you’ll see, the method now obtains the course name by calling a method in the same class—
1 // Fig. B.5: GradeBook.java ...