A variable of a primitive type contains the actual data, not information on where the data is.
Characteristics | |
---|---|
primitive variable | Contains the actual data. |
reference variable | Contains information on how to find the object. |
Here is the example program again:
class egString { public static void main ( String[] args ) { String str; str = new String( "The Gingham Dog" ); System.out.println( str ); } } |
When the line
System.out.println( str );
is executed (when the program is running),
the information stored in str
is used to go to the object and
get the data to be printed.