public class NewClass {
public String makinStrings() {
String s = "Fred";
s = s + "47";
s = s.substring(2, 5);
s = s.toUpperCase();
return s.toString();
}
}
How many objects are created in the above program? I see as 4 objects after converting to uppercase string, but the answer is 3 according scjp book. I don't understand how come only 3 objects
Yes 3 objects
If you see the source of
substring()andtoUpperCase()it returns a new string ands + "47";since the value ofsis determined at runtime it willl create new string so a total of 3 objects.