Answer:
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.
Two Objects
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
QUESTION 11:
How many objects were created by the program?
How many reference variables does the program contain?
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);
}
}