In the United States, daylight savings time ends on November 5th, 2017 at 02:00 a.m. and we repeat the previous hour. What is the output of the following?
import java.time.*; public class Main { public static void main(String[] args) { LocalDate localDate = LocalDate.of(2017, Month.NOVEMBER, 5); LocalTime localTime = LocalTime.of(1, 0); ZoneId zone = ZoneId.of("America/New_York"); ZonedDateTime z = ZonedDateTime.of(localDate, localTime, zone); for (int i = 0; i < 6; i++) z.plusHours(1); //from w ww.j a va 2 s .c om System.out.println(z.getHour()); } }
D.
This question is tricky.
It appears to be about daylight savings time.
However, the result of z.
plusHours(1)
is never stored in a variable or used.
Since ZonedDateTime is immutable, the time remains at 01:00.
The code prints out 1, making none of these correct and Option D the answer.