OCA Java SE 8 Mock Exam - OCA Mock Question 14








Question

Which of the following print out a date representing April 1, 2015? (Choose all that apply)

  1. System.out.println(LocalDate.of(2015, Calendar.APRIL, 1));
  2. System.out.println(LocalDate.of(2015, 4, 1));
  3. System.out.println(LocalDate.of(2015, 3, 1));
  4. System.out.println(LocalDate.of(2015, Month.APRIL, 1));
  5. System.out.println(new LocalDate(2015, 4, 1));
  6. System.out.println(new LocalDate(2015, 3, 1));




Answer



B, D.

Note

The new date APIs use static methods rather than a constructor to create a new date, E and F are incorrect.

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

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