Java OCA OCP Practice Question 1818

Question

Which correctly fills in the blank to print 2020-01-15?

LocalDate hatDay = LocalDate.of(2020, Month.JANUARY, 15); 
DateTimeFormatter f = DateTimeFormatter.ISO_DATE; 
System.out.println(___); 
I.   f.format(hatDay)
II.   f.formatDate(hatDay)
III.  hatDay.format(f)
  • A. I
  • B. III
  • C. I and III
  • D. II and III


C.

Note

Both LocalDate and DateTimeFormatter have a format() method.

This makes II incorrect.

While it is tricky, you do need to know that the format() method can be called on either object.

Since I and III are correct, Option C is the answer.




PreviousNext

Related