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 statement
System.out.println( str );
is executed,
the reference in str
is used to find the object and
get the data to be printed.
Does using str
in the above statement change the information in it?