OCA Java SE 8 Core Java APIs - OCA Mock Question Core Java APIs 2-2








Question

What is the output of the following code?

public class Main{
   public static void main(String[] argv){
         LocalDateTime d = LocalDateTime.of(2015, 5, 10, 10, 33, 44); 
         Period p = Period.ofDays(1).ofYears(2); 
         d = d.minus(p); 
         DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); 
         System.out.println(f.format(d)); 
   
   }
}
  1. 5/9/13 10:33 AM
  2. 5/10/13 10:33 AM
  3. 5/9/14
  4. 5/10/14
  5. The code does not compile.
  6. A runtime exception is thrown.




Answer



B.

Note

Period does not allow chaining. Only the last Period method called counts.