Larger Example

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        

Does using str in the above statement change the information in it?

Answer:

No. Using the information does not change it. This is the same as with a primitive variable: using it in an arithmetic expression does not change its information.

Larger Example

Here is a slightly larger version of the example program, now with a new variable of a primitive type:

class EgString2
{

  public static void main ( String[] args )
  {
    String str;
    long   value;
    
    str   = new String( "The Gingham Dog" );
    value = 32912;

    System.out.println( str   );
    System.out.println( value );
  }
}

When the statement

str   = new String( "The Gingham Dog" );

is executed, a new object is created and a reference to it is placed in str.

QUESTION 8:

What happens when the statement

value = 32912;

is executed?