This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String objects.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String objects.." Watch "String objects.." New topic

String objects..


Joined: Sep 14, 2000
Posts: 28
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..
Ranch Hand

Joined: Sep 12, 2000
Posts: 63
"pal" is also a literal that gets created in addition to s1 and s3.
I agree. Here's the link:
subject: String objects..
It's not a secret anymore!