• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

String Object

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many object will be created
<code>
String s1,s2,s3,s4;
s1="Hello";
s2=s1;
s3=s1+"Bill";
s4=s3;
</code>
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
Thanks

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Siva
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm closing this thread since it is a duplication of the other discussion http://www.javaranch.com/ubb/Forum24/HTML/009041.html
reply
    Bookmark Topic Watch Topic
  • New Topic