Java Reference
In-Depth Information
The following step enters code to create the overloaded constructors.
To Create Overloaded Constructors
1. Enter lines 25 through 55 as shown in Figure 9-9 on the previous page.
TextPad displays the code for the constructors in the coding window
(Figure 9-10). Each constructor creates a new ArrayList object to assign
to the instance variable of type ArrayList. The set() method called in each
constructor will be coded later.
new ArrayList
object
created in
each
constructor
set() method
called in each
constructor
FIGURE 9-10
The overloaded constructors now are completed. To complete the Password
class, however, additional instance methods are needed.
Understanding Accessor (Get) and Mutator (Set)
Methods
Recall that instance variables (attributes) typically are kept private in order to
support the concept of information hiding. Applications that will use the
Password class, also called user programs , do not need to know the specifics
of the instance attributes. Only methods within the class have access to private
variables, so user programs — that is, any object outside of the class — must call
instance methods of the class in order to gain access to the variables, either to
obtain or change their value. Typically, a class will provide methods strictly for
the purpose of obtaining or changing the value of instance variables.
 
Search WWH ::




Custom Search