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








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, 22, 33, 44); 
     Period p = Period.of(1, 2, 3); 
     d = d.minus(p); 
     DateTimeFormatter f = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); 
     System.out.println(d.format(f));    
   }
}
  1. 3/7/14 22:33 AM
  2. 5/10/15 22:33 AM
  3. 3/7/14
  4. 5/10/15
  5. 22:33 AM
  6. The code does not compile.
  7. A runtime exception is thrown.




Answer



E.

Note

The formatter only outputs time.

//from  www  .j a v a  2 s.com
public class Main{
   public static void main(String[] argv){
     LocalDateTime d = LocalDateTime.of(2015, 5, 10, 22, 33, 44); 
     Period p = Period.of(1, 2, 3); 
     d = d.minus(p); 
     DateTimeFormatter f = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); 
     System.out.println(d.format(f));    
   }
}

The code above generates the following result.