Answer:
a good walk spoiled.
A New String
Here is a picture of what happens as the program runs. When the program first 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 12:
Does running the substring() method of a String
change that String?