QuestionQ102

Working with Selected Classes from the Java API

Given this code fragment:

Question Image

What is the output?

  • A An exception is thrown at runtime.
  • B 07-31-2014
  • C 2014-07-31
  • D 2014-09-30
Explanation

LocalDateTime is immutable, so plusDays(30) and plusMonths(1) do not alter dt unless their returned values are assigned. dt therefore remains July 31, 2014, and DateTimeFormatter.ISO_DATE formats that date as 2014-07-31.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!