Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*;
    public class stack_Example
    {
    public static void main(String args[])
    {
    Stack object = new Stack();
    object.push(new Integer(20));
    object.push(new Integer(12));
    object.pop();
    object.push(new Integer(60));
    System.out.println(object);
    }
    }
    1. [20, 60]
    2. [20, 12, 60]
    3. [20, 12]
    4. [12, 60]
    5. None of these
Correct Option: A

push() and pop() are standard functions of the class stack, push() inserts in the stack and pop removes from the stack. 20 & 12 are inserted using push() the pop() is used which removes 12 from the stack then again push is used to insert 60 hence stack contains elements 20 & 60.



Your comments will be displayed only after manual approval.