What is the result?

Given the code fragment:

What is the result?
A. 2012-02-10
B. 2012-02-11
C. Compilation fails
D. A DateTimeException is thrown at runtime.

Download Printable PDF. VALID exam to help you PASS.

2 thoughts on “What is the result?

  1. D :
    #javac Test1.java
    #java Test1
    Exception in thread “main” java.time.DateTimeException: Invalid value for DayOfMonth (valid values 1 – 28/31): 32
    at java.base/java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
    at java.base/java.time.temporal.ChronoField.checkValidValue(ChronoField.java:717)
    at java.base/java.time.LocalDate.of(LocalDate.java:270)
    at Test1.main(Test1.java:4)
    To compile it successfully it also was needed to add “import java.time.LocalDate” and javac should be at least version 8

    1. Imports only matter if we see line 1: according to the official OCA book. If line # is not shown or if line begins anywhere after line1, we can safely assume all imports are present

Leave a Reply

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

The reCAPTCHA verification period has expired. Please reload the page.