File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Object" Watch "String Object" New topic

String Object


Joined: Apr 01, 2001
Posts: 5
How many object will be created
String s1,s2,s3,s4;
Answer given was 3. But according to me it is 2. Is that "Bill"
is also the object which is going in literal pool. PZ explain me

Siva Prasad
Ranch Hand

Joined: Feb 22, 2001
Posts: 104
The answer is 3
"Hello" is the 1st object
"Bill" is another object.
And the result of s1+"Bill" is another object.
so in total 3 objects will be created.
Remember Anju! String Objects in java are immutable. You cannot change the content of a string object in anyway.
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
I'm closing this thread since it is a duplication of the other discussion

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
I agree. Here's the link:
subject: String Object
It's not a secret anymore!