Java OCA OCP Practice Question 360

Question

Which of the following print out a date representing April 1, 2020?

Choose all that apply

  • A. System.out.println(LocalDate.of(2020, Calendar.APRIL, 1));
  • B. System.out.println(LocalDate.of(2020, Month.APRIL, 1));
  • C. System.out.println(LocalDate.of(2020, 3, 1));
  • D. System.out.println(LocalDate.of(2020, 4, 1));
  • E. System.out.println(new LocalDate(2020, 3, 1));
  • F. System.out.println(new LocalDate(2020, 4, 1));


B, D.

Note

The new date APIs added in Java 8 use static methods rather than a constructor to create a new date, making options E and F incorrect.

The months are indexed starting with 1 in these APIs, making options A and C incorrect.

Option A uses the old Calendar constants which are indexed from 0.

Options B and D are correct.




PreviousNext

Related