String string1, string2, string3;
string1 = new String(“StringObjects”);
string2 = string1;
string3 = string1 + string2;
How many String objects are created?
is it 2 or three? To my understanding for string literals an object will be created in the heap. Does this make the total number of objects 3 or two?
I believe the correct answer is 3, string 3 creates 1 object and string 1 creates 2 objects
New contributor
Nasima is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.