Java Reference
In-Depth Information
Figure 9
Rectangular Shapes
Figure 10
Rectangle
Objects
44
45
It is very important that you understand this distinction. In the computer, a
Rectangle
object is a block of memory that holds four numbers, for example x=5,
y=10, width=20, height=30. In the imagination of the programmer who uses a
Rectangle
object, the object describes a geometric figure.
Use the new operator, followed by a class name and parameters, to construct new
objects.
To make a new rectangle, you need to specify the x, y, width, and height values. Then
invoke the
new
operator, specifying the name of the class and the parameters that are
required for constructing a new object. For example, you can make a new rectangle
with its top-left corner at (5, 10), width 20, and height 30 as follows: