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

Answer:

a good walk spoiled.


A New String

picture showing object creation

The pictures show what happens as the program runs. When the program starts there are two reference variables, but no objects. When the first statement executes,

String str = new String( "Golf is a good walk spoiled." ); // create the original object

it creates a String object and puts a reference to that object in the variable str. (The picture shows only the data part of the objects.)

When the second statement executes,

String sub = str.substring(8); //create a new object from the original

a new object is created that contains a substring of the characters in the first object. The variable sub is assigned a reference to this object.


QUESTION 13:

Does running the substring() method of a String object change that String object?