Java OCA OCP Practice Question 1865

Question

What is a possible output of the following?

LocalDate date = LocalDate.of(2020, 5, 13); 
LocalTime time = LocalTime.of(10, 0); 
LocalDateTime trainDay = LocalDateTime.of(date, time); 
Instant instant = trainDay.toInstant(); 
instant = instant.plus(1, ChronoUnit.DAYS); 
System.out.println(instant); 
  • A. 2020-05-14T10:00-07:00[America/Los_Angeles]
  • B. 2020-05-14T17:00:00Z
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

An Instant represents a specific moment in time using GMT.

Since LocalDateTime does not have a time zone, it cannot be converted to a specific moment in time.

Therefore, the toInstant() call does not compile, and Option C is correct.




PreviousNext

Related