Java OCA OCP Practice Question 937

Question

What is the output of the following code?

import java.time.LocalDate;
import java.time.Month;

public class Main {
   public static void main(String[] args) {
      LocalDate date = LocalDate.of(2018, Month.APRIL, 40);
      System.out.println(date.getYear() + " " + date.getMonth() + " " + date.getDayOfMonth());

   }//from w w  w .j  a v a 2 s . c o  m
}
  • A. 2018 APRIL 4
  • B. 2018 APRIL 30
  • C. 2018 MAY 10
  • D. Another date.
  • E. The code does not compile.
  • F. A runtime exception is thrown.


F.

Note

Java throws an exception if invalid date values are passed.

There is no 40th day in April-or any other month for that matter.




PreviousNext

Related