Java Reference
In-Depth Information
Display 5.12
Class Type Variables Store a Reference
public class ToyClass
{
ToyClass sampleVariable;
Creates the variable
in
sampleVariable
private String name;
private int number;
The complete definition of the class
ToyClass is given in Display 5.11.
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
. 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
sampleVariable 2056
For emphasis, we made the
arrow point to the memory
location referenced.
2056 Josephine Student
42
 
Search WWH ::




Custom Search