Skip navigation.
Home

How many String objects will be created when this method is invoked?

 public String makinStrings() {

 String s = “Fred”;

 s = s + “47”;

 s = s.substring(2, 5);

 s = s.toUpperCase();

 return s.toString();

 }

Is this a quiz?

Is this a quiz?

if not, so take this note "String is immutable".
now you can count.

Ali Abdel-Aziz Ali
Software Engineer/OpenCraft
www.aliabdelaziz.com
 

are they five object or

are they five object or three?

I think they are 4.

I think they are 4.

Ali Abdel-Aziz Ali
Software Engineer/OpenCraft
www.aliabdelaziz.com
 

SCJP

It is one of the SCJP questions about the understanding of the String and StringBuffer objective.

The answer is 4 


Ahmed Hashim

Software Engineer

hashimblog/