Defining Classes
Previously, we examined how objects from a given class can be
instantiated and used. Our next goal is to look at the code which
defines a Class.
For this purpose, we will examine the CyberPet Case Study,
which is an ongoing example from the text. It is introduced in
Ch. 2, and expanded throughout
Ch. 3.
In class, we started with the initial version of the CyberPet, as
definined in Figure 2-8 and then built up to the version given in
Figure 3-10.
The outline of issues discussed in that context includes:
-
The Declaration of a Class
-
implicitly extends Object
-
delcaring instance variables
-
declaring class methods
-
Use of matching curly brackets ( { } ) to demarcate blocks of code
-
keywords: return, void
-
Qualified names (e.g., System.out.println(), csa120.shape.Canvas)
-
Scope of variables (e.g., class vs. local)
-
Variable initialization and default values
-
Constructor (this method name must be same as the class
name, and the return value is implicitly a reference to
the newly created object)
-
String contatenation operator
-
Use of parameters and return values
-
Constructor Overloading and Method Signatures
Michael Goldwasser
Last modified: Friday, 30 January 2004