Java Reference
In-Depth Information
The accessor method, getExpiresNotifyLimit(), in lines 79 through 82
returns the value of the instance variable, expiresNotifyLimit. The mutator
method, setExpiresNotifyLimit(), accepts an int value from the user program
and then verifies that the new value is within the acceptable range of values and,
if so, assigns the new value to the instance variable. Line 86 uses a logical AND
to test the parameter for a value between 2 and 20, inclusively, as specified in the
requirements document. If the new value is within the acceptable range, then the
code assigns the new value to the expiresNotifyLimit instance variable (line 87).
The following steps enter code for the accessor method and mutator method
for the expiresNotifyLimit instance variable of the Password class.
To Code Accessor and Mutator Methods
for the expiresNotifyLimit Instance Variable
1. Enter lines 79 through 82 as shown in Figure 9-17 on the previous page.
TextPad displays the accessor method for the expiresNotifyLimit instance
variable (Figure 9-18). The method is quite simple, as is common for
accessor methods.
return data
type matches
data type of
instance
variable
no parameter
accessor
method
returns current
value of instance
variable
FIGURE 9-18
2. Enter lines 84 through 88 as shown in Figure 9-17.
TextPad displays the mutator method for the expiresNotifyLimit instance
variable (Figure 9-19). Using a unique name for the parameter avoids a
name conflict with the instance variable.
single parameter data
type matches data type of
instance variable
method name
begins with set
method return
data type is void
unique parameter name
mutator
method
unique parameter name
instance
variable
FIGURE 9-19
 
Search WWH ::




Custom Search