Forums Register Login

String buffer

+Pie Number of slices to send: Send
hello all,

public class TestBuffer {
public void myBuf( StringBuffer s, StringBuffer s1) {
s.append(" how are you") ;
s = s1;
System.out.println("s in mybuf block is " +s);
}
public static void main ( String args[] ) {
TestBuffer tb = new TestBuffer();
StringBuffer s = new StringBuffer("Hello");
StringBuffer s1 = new StringBuffer("doing");
tb.myBuf(s, s1);
System.out.print("s is main block is : " +s);
}
}
The output is:-
s in mybuf block is doing.
s is main block is : Hello how are you.
So now, my question is that in mybuf method the value of s is changed to doing,then how i am getting the output as "Hello how are you" in main block,
please help,
thanks in advance.........
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 590 times.
Similar Threads
A String Buffer question,help!
don't understand
Queries
Question from Javacaps mock
I thought it should be "Hello" instead of "Hello how are you"
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:36:26.