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








Question

What is the output of the following code?

public class Main{
   public static void main(String[] argv){
         LocalDate date = LocalDate.of(2016, Month.APRIL, 30); 
         date.plusDays(2); 
         date.plusYears(3); 
         System.out.println(date.getYear() + " " 
            + date.getMonth() + " " + date.getDayOfMonth()); 
   }
}
  1. 2016 APRIL 2
  2. 2016 APRIL 30
  3. 2016 MAY 2
  4. 2019 APRIL 2
  5. 2019 APRIL 30
  6. 2019 MAY 2
  7. A runtime exception is thrown.




Answer



B.

Note

Since dates are immutable, and the result is unchanged.

//w w w. java  2 s. c o m
public class Main{
   public static void main(String[] argv){
         LocalDate date = LocalDate.of(2016, Month.APRIL, 30); 
         date.plusDays(2); 
         date.plusYears(3); 
         System.out.println(date.getYear() + " " 
           + date.getMonth() + " " + date.getDayOfMonth()); 
   }
}

The code above generates the following result.