QuestionQ28

Java SE APIs

Given the following code fragment:

Question Image

What is the output?

  • A PT5000SPT60MP6D
  • B PT5SPT1MP6D
  • C 5S1M6D
  • D 5000S60M6D
Explanation

Duration.toString() uses ISO-8601 time-based formatting, omitting zero-valued sections: 5,000 milliseconds is PT5S, and 60 seconds is PT1M. Period.toString() uses ISO-8601 date-based formatting, so six days is P6D. Consecutive print calls concatenate these values as PT5SPT1MP6D.

Learn more

Community Discussion

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