• 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

Doubt in Parameter Passing

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,

Please note the following program:


It is giving the following output:

S1 Before Append : Hello
S1 After Append : Hello How are you
S1 After S1=S2 : Doing
Final Output in Main Method : Hello How Are you.

Could you please explain me why it is NOT printing "Doing" in the last output (it has been changed to "doing" in the method myBuf() ?
In the statement "s1=s2", if s1 and s2 are local to the method myBuf(),
then why in the statement s1.append("how are you") , s1 is not local to the method myBuff().

I am a bit confused. A good explanation is GREATLY APPRECIATED.

Thanks in advance

Best Regards

Suresh
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
s1=s2; in the method is modifing the reference of s1 which is created in the method and that s1 is not same as the reference in the main method

 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have an FAQ which may help.
reply
    Bookmark Topic Watch Topic
  • New Topic