Java OCA OCP Practice Question 2249

Question

Given this code segment.

ZoneId zoneId = ZoneId.of("Asia/Singapore");
ZonedDateTime zonedDateTime =
        ZonedDateTime.of(LocalDateTime.now(), zoneId);
System.out.println(zonedDateTime.getOffset());

assume that the time-offset value for the Asia/Singapore time zone from UTC/Greenwich is +08:00.

Choose the correct option.

  • A. this code segment results in throwing DateTimeException
  • B. this code segment results in throwing UnsupportedTemporalTypeException
  • C. the code segment prints: Asia/Singapore
  • D. the code segment prints: +08:00
  • e. this code segment prints: +08:00 [Asia/Singapore]


D.

Note

given a ZonedDateTime object, the getOffset() method returns a ZoneOffset object that corresponds to the offset of the time zone from UtC/greenwich.

given that the time-offset value for the asia/singapore zone from UtC/greenwich is +08:00, the toString() method of ZoneOffset prints the string "+08:00" to the console.




PreviousNext

Related