• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help on strings urgent exams next week

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
i think 2, but the mock exam answer says 3 pls explain.
Thanx in advance
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Three strings are created i.e,
"Hello"
"Pal"
"HelloPal"
HTH
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,chin josei:
I also want to know the processs of creating these three object,can you describe it explicitly?thanks a lot.
 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think 3.....Following this process.
First Hello will be created.Understanding of this line should me made carefully,
s3 = s2 + "Pal";
Now compiler have to concate the two string objects.It will search the two strings first in the pool if it gots one then it will pick this & start searching another one.In both cases if String objects is not found it will create one by it self and then concate it with another one.
In this case it will pick the string object pointed by s2(i.e Hello) & make Pal by it self and then concate both Pal & Hello.If you analyse u will find that total of THREE objects is made altogether
This is my thinking....May be i am wrong.So plz. confirm it!
Bye.
Viki.

------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look at:
http://www.javaranch.com/ubb/Forum24/HTML/006269.html
it's the same question
Byez
 
Vikrama Sanjeeva
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks 4 confirming David.
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic