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.
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.
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
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