I'm doing a few mock test for my Oracle Certified Java Programmer certification. One of the question I found in a test is this one:
public String makinStrings() {
String s = “Fred”;
s = s + “47”;
s = s.substring(2, 5);
s = s.toUpperCase();
return s.toString();
}
And the question is "How many String objects will be created when this method is invoked?". I'm counting 5: "Fred", "47", "Fred47", the substring "ed4" and the uppercased string "ED4", but the question answer is 3 objects (and the document where the test is doesn't have an explanation section). Can you point where is my error?