Java Reference
In-Depth Information
If I speak of “My old car that is parked at home in my garage,” we can answer the questions
above. That car is red, it doesn't go very fast, and it is in my garage. Now I am talking about an
object—about one particular example of a car.
We usually refer to a particular object as an instance. We shall use the term “instance” quite
regularly from now on. “Instance” is roughly synonymous with “object”; we refer to objects as
instances when we want to emphasize that they are of a particular class (such as “this object is
an instance of class car”).
Before we continue this rather theoretical discussion, let us look at an example.
1.2
Creating objects
Start BlueJ and open the example named figures. 1 You should see a window similar to that
shown in Figure 1.1.
Figure 1.1
The figures project
in BlueJ
In this window, a diagram should become visible. Every one of the colored rectangles in the dia-
gram represents a class in our project. In this project, we have classes named Circle , Square ,
Triangle , and Canvas .
Right-click on the Circle class and choose
new Circle()
from the pop-up menu. The system asks you for a “name of the instance”; click OK—the de-
fault name supplied is good enough for now. You will see a red rectangle toward the bottom of
the screen labeled “circle1” (Figure 1.2).
1 We regularly expect you to undertake some activities and exercises while reading this topic. At this
point, we assume that you already know how to start BlueJ and open the example projects. If not, read
Appendix A first.
 
 
Search WWH ::




Custom Search