Java OCA OCP Practice Question 1853

Question

What does the following print?

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

public class PolarBear { 
   public static void main(String[] args) { 
      LocalDate polarBearDay = LocalDate.of(2020, 2, 27); 
      DateTimeFormatter formatter = DateTimeFormatter 
         .ofPattern("Holiday: yyyy dd MMM"); 
      System.out.println(polarBearDay.format(formatter)); 
   } /*ww w.j a  v  a  2 s  .c om*/
} 
  
  • A. Holiday: 2020 27 Jan
  • B. Holiday: 2020 27 Feb
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


D.

Note

The format of the pattern is incorrect.

You can't just put literal text in there.

Most of the characters of Holiday: are not defined formatting symbols.

The code throws an IllegalArgumentException, so Option D is correct.




PreviousNext

Related