Java Reference
In-Depth Information
The following step enters the declaration statements for the class variables.
To Enter Declarations for the Rooms Class
1. Enter the code as shown in Figure 5-9 on the previous page.
The TextPad window displays the variable declarations for the int variables,
numSmoking and numNonSmoking, and the boolean array, occupied
(Figure 5-10).
variable
declarations
FIGURE 5-10
Constructing an Instance
Declaring variables in the external class, Rooms, is not sufficient to make Rooms a
reusable object. A class is just an abstract description of what an object will be like
when the object is instantiated, or created. This kind of class definition is like a
blueprint for the object. Just as you might understand all the characteristics of an
item you intend to manufacture long before the first item rolls off the assembly
line, you describe a class before you create a working instance of that class.
Recall that an instance is a unique object or a specific occurrence of a class
of objects. You can think of an instance as a proper noun. For example, the
word, boy, is a noun; but the word, John, is a proper noun. John defines which
boy you are talking about. In Java, declaring the variables for a class indicates
that the code will include an object (or, as in the example, a noun, boy). Using a
constructor method, you then will define a specific instance of that object (or, as
in the example, the proper noun, John).
Search WWH ::




Custom Search