• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

StringBuffer assigment

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the output when you compile and run the following code?
public class Sup{
public static void main(String args[]){
StringBuffer sb1=new StringBuffer("Hello");
StringBuffer sb2=new StringBuffer("Hello");
aMethod(sb1,sb2);
System.out.println("sb1 is"+sb"\n"+"sb2 is"+sb2);
}
public static void aMethod(StringBuffer b1,StringBuffer b2){
b2.append(" three");
b1=b2;
}
}
The ans is:
sb1 is Hello
sb2 is Hello there
I don't know why? Because b1=b2 My ans is
sb1 is Hello there
sb2 is Hello there
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see this post... http://www.javaranch.com/ubb/Forum24/HTML/003951.html
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
 
reply
    Bookmark Topic Watch Topic
  • New Topic