Author Topic:   Stack
posted March 10, 2000 03:50 PM             
What is the output when you try to print out each Stack.

A class was given in the main() method:
Stack s1=new Stack();
Stack s2=new Stack();
System.out.println("s1" + s1+" "+ "s2" + s2);
public static void method(Stack s1,Stack s2){
s1.push(new Integer(100));
A. Compile error.
B. Runtime error.
C. s1[100]s2[100]
D. s1[ ]s2[ ]
E. s1[100]s2[ ]
F. s1[ ]s2[100]

This is from Kai's note. Is the answer E ??

maha anna
posted March 10, 2000 03:59 PM             
Yes. The ans is s1[100] s2[].
These are all can be easily found by compiling and executing. In that way we come to understand the concept quickly and easily. By making modifications to the code and testing, you know yourself which is correct. You do not have to ask again yourself.
maha anna

Tony Alicea
posted March 10, 2000 04:00 PM             
If you mean does the stack denoted by the variable s1 have an Integer of value of 100 and the second stack nothing? I think that's correct.

The s1 and s2 inside the method are just local variables and although you can change the state of the objects which they denote, you cannot change the values associated with them outside of the method.