Hi all,
public class TestBuffer
{
public static void main(String args[]) {
StringBuffer a = new StringBuffer("One");
StringBuffer b = new StringBuffer("Two");
TestBuffer t = new TestBuffer();
t.swap(a,b);
System.out.println("a is "+ a +"\nb is " + b);
}
static void swap (StringBuffer a, StringBuffer b) {
a.append(" more");
b=a;
}
}
Answer is
---------
What will be the output?
Answer:
a. a is One
b is Two
b. a is One
b is One
c. a is One more
b is One more
d. a is One more
b is Two
e. a is One more
b is Two more
The given answer is 'd' and my answer is 'c'. When I executed the program it gives 'd'.
I modified program like as follows to know the intermediate result:
static void swap (StringBuffer a, StringBuffer b) {
a.append(" more");
System.out.println("Before assign a is "+ a +"\nb is " + b);
b=a;
System.out.println("After Assign a is "+ a +"\nb is " + b); Before assignment ,I am getting ' Before assign a is one more ' and 'b is two'.
After assignment,I am getting ' Before assign a is one more ' and 'b is one more'.
Then how come,when it goes to main it prints
a is one more and
b is two.
Please help me.
I could not run the 'sample
test',it says 'File not found' 3 times and file creation error 2 times and bad command or file name.
I created director Jargon and uninstall 'install.zip'. Now this directory has 'jargon.zip','sarg.dat' and 'run.bat'. I checked resolution and it is fine. And try running like follows from c:\jdk1.2.1\bin\
java -jar c:\Jargon\jargon.zip. Same error I am getting.
Please help me and bear this big mail.
Thanks in advance
Nirmala