HL ; computer programming ; all languages
Sunday, November 21, 2010
Java - Example - mechanism to note: method in a Class calling another method in the same Class
mechanism to note: method in a Class calling another method in the same Class
Java - Example - A Class with an Instance Variable, a set Method and a get Method
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"
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"
Subscribe to:
Posts (Atom)