Monday, 15 December 2014

// The "StringObjectsExample3" class.  Page 350.
// Example 3.  (from the Carter book)

// View the program fragment that follows:

public class StringObjectsExample3
{
    public static void main (String[] args)
    {
        String s = "Hello";
        s = "Bonjour";
        // first sets the variable "s" to refer to a String object
        // containing the value "Hello" and then sets "s" to refer
        // to a new String object containing the value "Bonjour".
        // At this point, the object containing the value "Hello"
        // is now lost.  The result is illustrated in the diagram
        // located in the middle of page 350.  Although the String
        // containing the value "Hello" still exists, it is no longer
        // accessible.

    } // main method
} // StringObjectsExample3 class

No comments:

Post a Comment