go to previous page   go to home page   go to next page hear noise highlighting

Answer:

No. The statement

str = value ;

is (apparently) asking that the primitive long 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:

two stuffed pillows
public 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?


go to previous page   go to home page   go to next page