What is the output of the following?
LocalDate date = LocalDate.of(2020, Month.JULY, 17);
LocalTime time = LocalTime.of(10, 0);
ZoneId zone = ZoneId.of("America/New_York");
ZonedDateTime iceCreamDay = ZonedDateTime.of(date, time, zone);
date = date.plusMonths(1);
System.out.println(iceCreamDay.getMonthValue());
B.
This code begins by correctly creating four objects.
It then adds a month to date.
Since Java 8 date/time classes are immutable, this does not affect the value of iceCreamDay
.
Therefore, iceCreamDay
remains in July.
Since months count from one, Option B is correct.