Suppose a driver program creates and uses a Stack like this
Suppose a driver program creates and uses a Stack like this. What will print? Stack myStack = new Stack0; String result; myStack.push(\"AAA\"); myStack.push(\"BBB\"); result = myStack.popO; result = myStack. peekO; myStack.pushf\'CCC\'); result = myStack.popO; System.out.println(result); AAA CCC BBB an exception will be thrown.
Solution
Answer: CCC
first we inserted Strings \"AAA\" and \"BBB\" into stack. After that we perform peek() method. it will return the top element in stack so it will return BBB as per flast in first out mechanism. after that we applied pop() method. it will remove top element in stack. So \"BBB\" will be removed. After that we inserted string \"CCC\" so now stack elements are \"CCC\", \"AAA\". Again applied pop. it will remove top element so \"CCC\" will be removed. So result will hold \"CCC\".
