OCA Java SE 8 Core Java APIs - OCA Mock Question Core Java APIs 3-6








Question

Which of the following can be inserted into the blank to create a date of June 21, 2016?

     import java.time.*; 

     public class Main { 
       public static void main(String[] args) { 
          LocalDate date = __
       } 
     }
  1. new LocalDate(2016, 5, 21);
  2. new LocalDate(2016, 6, 21);
  3. LocalDate.of(2016, 5, 21);
  4. LocalDate.of(2016, 6, 21);
  5. LocalDate.of(2016, Calendar.JUNE, 21);
  6. LocalDate.of(2016, Month.JUNE, 21);




Answer



D, F.

Note

Options A and B are incorrect because LocalDate does not have a public constructor.

Option C is incorrect because months start counting with 1 rather than 0.

Option E is incorrect because Calendar.JUNE counts months from 0.