posted 22 years ago
I am confused of this Q, Please help me!!!
Q: What is the output of the following fragment.
//A class was given in the main() method:
Stack s1=new Stack();
Stack s2=new Stack();
method(s1,s2);
System.out.println("s1" + s1+" "+ "s2" + s2);
public static void method(Stack s1,Stack s2){
s1.push(new Integer(100));
s2=s1 //Line 1
}
A. Compile error.
B. Runtime error.
C. s1[100]s2[100]
D. s1[ ]s2[ ]
E. s1[100]s2[ ]
F. s1[ ]s2[100]
Answer is E, but i think C should be correct. Because in Line 1, s2 points to s1, so i think s2 should have the same elements as s1. Please throw light on this issue. Thanks a lot.
(Hysterical screams removed from topic title)
[ December 07, 2004: Message edited by: Barry Gaunt ]