No. The statement
str = value ;
is (apparently) asking that the primitive data type contained in value
be placed in the reference variable str
.
This cannot be done.
Here is a further modification of the example program:
class EgString3 { public static void main ( String[] args ) { String str; str = new String("The Gingham Dog"); System.out.println(str); str = new String("The Calico Cat"); System.out.println(str); } }
The program does exactly what you would expect. It writes out:
The Gingham Dog The Calico Cat
How many objects were created by the program?
How many reference variables does the program contain?