My understanding is that Stack possesses LIFO property. And, based upon that I have written the following program:// This is a sample program to demonstrate push and pop// functionality in Stack in Java.package collections;public class Stack_Array {    private static final int capacity = 3;    int[] arr = new int[capacity];    int top = -1;    public void push(int pushedElement) {        if(top >= capacity) {            System.out.println(StackOverflow !!);        } else {            top++;            arr[top] = pushedElement;        }    }    public void pop() {        if(top>=0) {            top--;                  } else {            System.out.println(Stack underflow !!);        }    }    public void printStack() {        System.out.println(Elements in Stack are: );        for(int i = top; i >=0; i--) {            System.out.println(arr[i]);        }    }    public static void main(String[] args) {        Stack_Array s1 = new Stack_Array();        s1.push(23);        s1.push(21);        s1.push(14);        s1.pop();        s1.printStack();    }}Please let me know if it is the correct approach. Or, is there a better way to implement the same
Stack implementation, array-based
java;stack