Java OCA OCP Practice Question 1859

Question

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()); 
  • A. 6
  • B. 7
  • C. 8
  • D. The code does not compile.


B.

Note

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.




PreviousNext

Related