Java OCA OCP Practice Question 1839

Question

Which statement is not true about these two variables?

Duration duration = Duration.ofDays(1); 
Period period = Period.ofDays(1); 
  • A. Both output the same value when calling toString().
  • B. The Duration object compiles because durations are for smaller units of time.
  • C. The Period object compiles because periods are for larger units of time.
  • D. None of the above


A.

Note

Duration is used for units of time a day and smaller, making Option B a true statement.

Period is used for units of time a day and larger, making Option C a true statement.

While both represent the same length of time, they output different values when calling toString().

The Duration object outputs PT24H, and the Period object outputs P1D.

This shows that Duration is providing the ofDays() method as a convenience instead of requiring the programmer to type 24 hours.

Option A is the answer.




PreviousNext

Related