Java Reference
In-Depth Information
An object's attributes are the values it stores internally, which may
be represented as primitive data or as other objects. For example, a
bank account object may store a floating point number (a primitive
value) that represents the balance of the account. It may contain
other attributes, such as the name of the account owner. Collectively,
the values of an object's attributes define its current state.
As mentioned earlier in this chapter, a method is a group of programming
statements that is given a name. When a method is invoked, its statements are
executed. A set of methods is associated with an object. The methods of an object
define its potential behaviors. To define the ability to make a deposit into a bank
account, we define a method containing programming statements that will update
the account balance accordingly.
An object is defined by a class. A class is the model or blueprint from which
an object is created. Consider the blueprint created by an architect when design-
ing a house. The blueprint defines the important characteristics of the house—its
walls, windows, doors, electrical outlets, and so on. Once the blueprint is created,
several houses can be built using it, as depicted in Figure 1.22.
In one sense, the houses built from the blueprint are different. They are in
different locations, have different addresses, contain different furniture, and are
inhabited by different people. Yet in many ways they are the “same” house. The
KEY CONCEPT
Each object has a state, defined by
its attributes, and a set of behaviors,
defined by its methods.
FIGURE 1.22
A class is used to create objects just as a house blueprint is
used to create different, but similar, houses
 
 
Search WWH ::




Custom Search