Java Reference
In-Depth Information
To Create Class and Instance Variables
1. Enter lines 1 through 16 as shown in Figure 9-5 on the previous page.
In the comments, insert your own name as programmer and enter the
current date.
TextPad displays code for the initial comments, import statement, class
header, and class variables in the coding window (Figure 9-6). The first two
variables are constants because of the keyword, final, while the next two are
not. The indentation used helps to make the distinction more noticeable.
initial comments
all capitals used
for final variables
import statement
variables
made constant
class variables
FIGURE 9-6
2. Enter lines 17 through 24 as shown in Figure 9-5.
TextPad displays the code for the instance variables in the coding window
(Figure 9-7). The instance variable of type ArrayList required the import of
java.util.* to make the ArrayList class from this package available for use in
the class.
import statement
instance
variables
reference variable
of type ArrayList
FIGURE 9-7
The code entered in the previous steps sets the initial values of the class and
instance variables to match the requirements defined in the requirements document
in Figure 9-2 on page 541. For example, the maxHistory variable is set to 4, so that
 
Search WWH ::




Custom Search