Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Hard

Question 43

Given code of Test.java file: 

What will be the result of compiling and executing Test class?

  • A [A]
  • B Runtime Exception
  • C []
Reveal correct answer

Correct answer: B

Explanation

Deque's add() method invokes addLast(E) method and remove() method invokes removeFirst() method.


chars.add('A'); => [A], 

chars.remove(); => [], 

chars.remove(); => No elements left to remove() and hence java.util.NoSuchElementException is thrown at runtime.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need