Class 1, Part 2 |
Intro to Java 30-IT-396 |
|
Object Construction
-
We know that we use constructors to make objects out of classes.
In other words, constructors are when we ink our stamp and stamp a piece
of paper with it. We use constructors to initialize values.
-
Further, we know that we can only call constructors with the new keyword.
We cannot access them via objectName.objectName().
-
If we do not specify a constructor, Java will provide the default (no argument)
constructor for us.
-
But keep in mind, if you do have a constructor with arguments, Java does
not provide the default constructor. So if you want both, you must
specify both!
-
However, we can make multiple constructors via overloading.
-
With overloading, we have multiple constructors that accept different parameters.
Thus, they have different signatures.
-
Take a look at the Integer
object. Note that we can create a new Integer object with either
a String or an int.
-
If you do not initialize a field, Java will set it to its default.
-
ints are 0, booleans are false, and objects are null.
-
But, don't rely on this. It is poor programming (and will count for
points off on the assignment!)
Using Multiple Files


Created by: Brandan
Jones January 4, 2002