• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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!
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic