This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Can anyone tell me the answer for this and explain it. 1. What is the output of this statement StringBuffer sb = new StringBuffer("A"); StringBuffer sb2 = new StringBuffer("B"); testString(sb, sb2); System.out.println("sb= " + sb + "\nsb2= " + sb2); static void tellme(StringBuffer sb, StringBuffer sb2) { sb2.append("A"); sb2 = sb; } Thanks, Srini
Angela Lamb
Ranch Hand
Joined: Feb 22, 2001
Posts: 156
posted
0
The output is sb = A sb2 = BA. Remember that everything is passed by value in Java, so the statement sb2 = sb changes the object reference in the method, but not the actual StringBuffer object that it is pointing to.
srini bhav
Greenhorn
Joined: Feb 20, 2001
Posts: 12
posted
0
Thanks for your answer but do you know about this teststring method ?
Jyotsna Clarkin
Ranch Hand
Joined: Jan 26, 2001
Posts: 158
posted
0
There appears to be an error naming the methods in this code since the parameter lists are the same their names should be identical. If you change the name of one to match the other the code will compile and give the output
Originally posted by srini bhav: testString(sb, sb2); static void tellme(StringBuffer sb, StringBuffer sb2) { sb2.append("A"); sb2 = sb; }
srini bhav
Greenhorn
Joined: Feb 20, 2001
Posts: 12
posted
0
Thanks Jyotsna . This was really driving me crazy. I thought that was a method defined in the String class. Srini
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.