Java OCA OCP Practice Question 1822

Question

Given that daylight savings time starts on March 12, 2017, at 2 a.m. and clocks jump from 1:59 a.m. to 03:00 a.m.,

which of the following can fill in the blank so the code doesn't throw an exception?

LocalDate localDate = LocalDate.of(2017, 3, 12); 
LocalTime localTime = LocalTime.of(                              ); 
ZoneId zone = ZoneId.of("America/New_York"); 
ZonedDateTime z = ZonedDateTime.of(localDate, localTime, zone); 
  • A. 2, 0
  • B. 3, 0
  • C. Either of the above will run without throwing an exception.
  • D. Both of these will cause an exception to be thrown.


C.

Note

While there is no 2 a.m. on the clock that night, Java adjusts the time to 3 a.m. automatically and changes the time zone.

It does not throw an exception, so Option D is incorrect.

Option B is a valid expression, since any value after the time adjustment is just a normal time on the clock.

Since both A and B are valid expressions, Option C is the correct answer.




PreviousNext

Related