Oracle Certified Professional Java Se 11 Developer · Free Practice Question Medium

Question 44

Question ID: UKOCP35329


Given code of Test.java file:


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

  • A

    STOP

    READY TO STOP

    GO

  • B

    GO

    STOP

    READY TO STOP

  • C

    GO

    READY TO STOP

    STOP

  • D Printing order cannot be predicted
Reveal correct answer

Correct answer: A

Explanation

UKOCP35329:

TreeMap is the sorted map on the basis on natural ordering of keys (if comparator is not provided). 


enum TrafficLight is used as a key for TreeMap. The natural order for enum elements is the sequence in which they are defined. Value corresponding to 'RED' is printed first, followed by value corresponding to 'YELLOW' and finally value for 'GREEN' is printed.

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