class GenericStackArray<T> { private T[] stackArray; private int top; private int maxSize; @SuppressWarnings("unchecked") public GenericStackArray(int size) { this.maxSize = size; this.stackArray = (T[]) new Object[maxSize]; this.top = -1; } public void push(T item) { if (top < maxSize - 1) { stackArray[++top] = item; } else { System.out.println("Stack Overflow"); } } public T pop() { if (top >= 0) { return stackArray[top--]; } else { System.out.println("Stack Underflow"); return null; } } public boolean isEmpty() { return top == -1; } }