This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Strings

 
prarthana reddy
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please have a look at the following question:

How many String objects are created when we run the following code.

String s1,s2,s3,s4;
s1 = "Hello";
s2 = s1;
s3 = s2 + "Pal";
s4 = s3;

can anyone please give me the answer ?
 
Naina Si
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
two objects
 
Naseem Khan
Ranch Hand
Posts: 809
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Three objects created here.

"Hello" and "Pal" is created at class load time as they are compile time constants, "HelloPal" at the time of the execution of the class.

Naseem
 
cathymala louis
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Three objects created.
1. Hello
2. pal
3. Hello pal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic