String a; Point b;
a
?
a
holds a reference to a String
object.b
holds a reference to a Point object.null
ValueA reference variable holds information about the location of an object. It does not hold the object itself. This code
String a; Point b;
declares two reference variables but does not construct any objects. The following constructs objects and puts references in the variables:
a = "Elaine the fair." ; b = new Point( 23, 491 );
A special value called null
is assigned to an object reference variable when it
does not refer to an object.
The valuenull
is a special value that means "no object." Your program should set a reference variable tonull
when it is not referring to any object.
(Thought Question:) Do you think that null
can be
assigned to reference variables of any type?
Click here for a .