Java OCA OCP Practice Question 753

Question

What is the result of the following?

import java.time.*; 
import java.time.format.*; 
? 
public class Main { 
   public static void main(String[] args) { 
      LocalDate newYears = LocalDate.of(2020, 1, 1); 
      Period period = Period.ofDays(1); 
      DateTimeFormatter format = DateTimeFormatter.ofPattern("mm-dd-yyyy"); 
      System.out.print(format.format(newYears.minus(period))); 
   } /*from  w w  w  .ja  va 2 s  .  c  o  m*/
} 
  • A. 01-01-2020
  • B. 12-31-2019
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


D.

Note

When creating a formatter object, remember that MM represents month while mm represents minute.

Since there are not minutes defined on a LocalDate object, the code throws an UnsupportedTemporalTypeException.




PreviousNext

Related