In this example, our class maintains the course name as an instance variable, so that it can be used or modified at any time during our application's execution.
Our class contains 3 methods - setCourseName, getCourseName, and displayMessage.
The method setCourseName stores a course name in a GradeBook (on object instance of our class)
The method getCourseName obtains a GradeBook's course name.
The method displayMessage, which now has no parameters being passed into it, still displays a welcome message, but also includes the course name of that object in the welcome message => what you should note is, displayMessage now obtains the course name be calling another method in the same class [ the getCourseName method] !!
Reference: "Java How to Program, by Deitel & Deitel"
No comments:
Post a Comment