Dog provides set-style access methods for modifying an instance variable. At times, it's necessary to retrieve an instance variable's value. Typically, if a class has instance variables that support set operations, they support get operations as well. For each of our set methods, we should code a corresponding get method, for example,
boolean getObedienceTrained() {
return obedienceTrained;
}
Note that in the case of boolean instance variables such as obedienceTrained, some programmers prefer the is-style naming convention over the get-style and some programmers like to provide both:
boolean isObedienceTrained() {
return obedienceTrained;
}
Note that isGoodWithChildren() from the previous panel is not really an access method--it does not return (report) an instance variable's value. Instead, it combines higher level, meaningful information with respect to an instance of the class Dog.
Exercise
copyright 1996-2000 Magelang Institute dba jGuru