Java Reference
In-Depth Information
To Code Accessor and Mutator Methods for the expired Instance
Variable
1. Enter lines 69 through 72 as shown in Figure 9-14.
TextPad displays the accessor method for the expired variable (Figure 9-15).
The method name begins with is, rather than get.
method name
begins with is
accessor
method
FIGURE 9-15
2. Enter lines 74 through 77 as shown in Figure 9-14.
TextPad displays the mutator method for the expired variable (Figure 9-16).
Using a unique name for the parameter avoids a name conflict with the
instance variable.
instance variable
mutator
method
parameter variable
FIGURE 9-16
expiresNotifyLimit ACCESSOR AND MUTATOR METHODS
Figure 9-17 displays the accessor method and mutator method for the
expiresNotifyLimit instance variable of the Password class. Recall that the number
contained in this variable is used to determine if the password will expire soon.
79
public int getExpiresNotifyLimit ()
80
{
81
return expiresNotifyLimit;
82
}
83
84
public void setExpiresNotifyLimit ( int newNotifyLimit )
85
{
86
if ( newNotifyLimit >= 2 && newNotifyLimit <= 20 )
87
expiresNotifyLimit = newNotifyLimit;
88
}
FIGURE 9-17
 
Search WWH ::




Custom Search