vendredi 27 février 2015

String objects count SCJP

Another exam question that makes me confused:



public String makinStrings() {
String s = “Fred”;
s = s + “47”;
s = s.substring(2, 5);
s = s.toUpperCase();
return s.toString();
}


the question is: "How many String objects will be created when this method is invoked?"


correct answer is supposed to be 3 but I counted more:

Fred

47

Fred47

ed4

ED4


is 3 really the correct answer? If so - why?


Aucun commentaire:

Enregistrer un commentaire