Java OCA OCP Practice Question 1847

Question

What is a possible result of the following?

LocalDate montyPythonDay = LocalDate.of(2020, Month.MAY, 10); 
LocalTime time = LocalTime.of(5, 40); 
LocalDateTime dateTime = LocalDateTime.of(montyPythonDay, time); 
Duration duration = Duration.ofDays(1); 
LocalDateTime result = dateTime.minus(duration); 
System.out.println(result); 
  • A. 2020-05-09
  • B. 2020-05-09T05:40
  • C. 2020-05-10T05:40
  • D. None of the above


B.

Note

This code correctly subtracts a day from montyPythonDay.

It then outputs a LocalDateTime value.

Option A is incorrect because it omits the time.

Option B is correct because it represents one day earlier than the original date and includes a time in the output.




PreviousNext

Related