What is the result?

Given:

import java.util.ArrayDeque;

import java.util.Deque;

public class Counter {

public static void main(String[] args) {

Deque<String> deq = new ArrayDeque<String>(2);

deq.addFirst(“one”);

deq.addFirst(“two”);

deq.addFirst(“three”); // Line 9

System.out.print(deq.pollLast());

System.out.print(deq.pollLast());

System.out.print(deq.pollLast()); // Line 12

}

}

What is the result?

Given:

import java.util.ArrayDeque;

import java.util.Deque;

public class Counter {

public static void main(String[] args) {

Deque<String> deq = new ArrayDeque<String>(2);

deq.addFirst(“one”);

deq.addFirst(“two”);

deq.addFirst(“three”); // Line 9

System.out.print(deq.pollLast());

System.out.print(deq.pollLast());

System.out.print(deq.pollLast()); // Line 12

}

}

What is the result?

A.
An exception is thrown at runtime on line 9.

B.
An exception is thrown at runtime on line 12

C.
one two null

D.
one two three

E.
two one null

F.
three two one



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Peter

Peter

D, but without spaces

gelete

gelete

D

Output : onetwothree