Reading Class Documentation
Reading and Using Constructors
- A class may have multiple constructors if the parameters are
different. (Example: AquaFish)
-
Constructors always have the same name as the class.
You construct an object with the
new
keyword and the
constructor.
- The simplest constructors have no parameters.
- Clock Class Documentation:
- Constructing a Clock object:
Clock myClock = new Clock();
- The class documentation might specify parameters, giving the
type and a descriptive name for each parameter. When constructing
an object, provide parameters of the correct type. (Names do not
matter.)
- Aquarium Class Documentation:
- Constructing an Aquarium object:
Aquarium fishTank = new Aquarium(600, 400);
- AquaFish Class Documentation:
- Constructing an AquaFish object:
AquaFish fish1 = new AquaFish(fishTank);
AquaFish fish2 = new AquaFish(fishTank, Color.RED);
Alyce Brady, Kalamazoo College