class MyStack { // This is now an array of Object's. Object[] stack; int stackTop; public void initialize () { stack = new Object [100]; } // Note: the parameter is now of type Object: public void push (Object value) { // A shorter version of push using the pre-increment operator. stack[++stackTop] = value; } // Note: the return value is now of type Object: public Object pop () { Object value = stack[stackTop]; stackTop --; return value; } public boolean isEmpty () { if (stackTop < 0) { return true; } else { return false; } } } public class StackExample3 { public static void main (String[] argv) { MyStack stack = new MyStack (); stack.initialize (); // Dump strings on stack. A String is an Object, so // it's OK to put strings. stack.push ("Alice"); stack.push ("Bob"); stack.push ("Chen"); while (! stack.isEmpty ()) { // Notice the cast required from Object to String. String name = (String) stack.pop (); System.out.println ("Removed " + name); } } }