class MyStack { StackDataType [] stack; int stackTop; // Define a constructor to initialize. // Note: a constructor has the same name as the class and no // return type. public MyStack () { stack = (StackDataType[]) new Object [100]; } public void push (StackDataType value) { stack[++stackTop] = value; } public StackDataType pop () { StackDataType value = stack[stackTop]; stackTop --; return value; } public boolean isEmpty () { if (stackTop < 0) { return true; } else { return false; } } } public class StackExample5 { public static void main (String[] argv) { // Now MyStack can be defined to accept only String's. MyStack stack = new MyStack (); // Don't need to explicitly initialize. stack.push ("Alice"); stack.push ("Bob"); stack.push ("Chen"); while (! stack.isEmpty ()) { // No cast required. String name = stack.pop (); System.out.println ("Removed " + name); } } }