Java OCA OCP Practice Question 1843

Question

What does the following print?

import java.time.*; 
import java.time.format.*; 

public class Main { 
   public static void main(String[] args) { 
      LocalDate polarBearDay = LocalDate.of(2020, 2, 27); 
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy dd MMM"); 
      System.out.println(polarBearDay.format(formatter)); 
   } /* w  ww .  j  a v  a  2 s . co m*/
} 
  • A. 2020 27 Jan
  • B. 2020 27 Feb
  • C. 2020 Jan 27
  • D. 2020 Feb 27


B.

Note

LocalDate starts counting months from one, so month 2 is February.

This rules out Options A and C.

The pattern specifies that the date should appear before the month, making Option B correct.




PreviousNext

Related