Two Objects

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

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:

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