Java Reference
In-Depth Information
Display 5.12
Class Type Variables Store a Reference
public
class
ToyClass
{
private
String name;
private
int
number;
The complete definition of the class
ToyClass
is given in Display 5.11.
ToyClass sampleVariable;
Creates the variable
sampleVariable
in
memory but assigns it no value.
sampleVariable
?
sampleVariable =
new
ToyClass("Josephine Student", 42);
Creates an object, places the object someplace in memory, and then
places the address of the object in the variable
sampleVariable
. We
do not know what the address of the object is, but let's assume it is
2056
. The exact number does not matter.
sampleVariable
2056
For emphasis, we made the
arrow point to the memory
location referenced.
2056
Josephine Student
42