Vidyalelo
Data Structure · Q174

Introduction to Data Structures

Programming · Data Structure · question 174

Q174

What is the output of the following program? public class Stack protected static final int CAPACITY = 100; protected int size,top = -1; protected Object stk[]; public Stack() stk = new Object[CAPACITY]; public void push(Object item) if(size_of_stack==size) System.out.println("Stack overflow"); return; else top++; stk[top]=item; public Object pop() if(top<0) return -999; else Object ele=stk[top]; top--; size_of_stack--; return ele; public class StackDemo public static void main(String args[]) Stack myStack = new Stack(); myStack.push(10); Object element1 = myStack.pop(); Object element2 = myStack.pop(); System.out.println(element2);

A.
stack is full
B.
20
C.
0
D.
-999
Answer

Answer: Option D

Solution

Answer: Option D
No explanation is given for this question Let's Discuss on Board