The above program demonstrates how to use Stack Collections in java. The below example defines a Stack Object which adds the object of Circle12 and Rectangle.The push() method is used to insert an object unto the the stack wheras the pop() method removes an object from the stack.The peek() method returns the object which is on top of the stack.
Run It Now!