• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String objects..

 
ramani2020
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
pl help me with the foll qn.
How many String literals are created when the foll code is executed and run?
String s1, s2,s3,s4 ;
s1 = "hello";
s2 = s1;
s3 = s2+"pal";
s4 = s3;
A. 1
B. 2
C. 3
D. 4
E. Can't say
IMO since only s1 and s3 are created,and the rest are assigned, the answer is B. Am I right?
please help me..
thanks,
Ramani.
 
srikrish
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"pal" is also a literal that gets created in addition to s1 and s3.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic