Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Constructors
-
Constructors run when the class is instantiated.
-
They have the same name as the class itself, but no return value.
-
You must use constructors with the new keyword, you cannot call
them directly.
-
Example:
Car myCar = new Car(); //ok
myCar.Car(); // not ok!
-
Constructors can take explicit parameters (the parameters between the ()).
And, you may have multiple constructors, each with a different signature.
-
Constructors cannot return a value.
More Constructors


Created by: Brandan
Jones January 4, 2002