Java OCA OCP Practice Question 1851

Question

What is the output of the following?

LocalDate date1 = LocalDate.of(2017, Month.MARCH, 3); 
LocalDate date2 = LocalDate.of(2017, Month.FEBRUARY, 31); 
System.out.println(date1.equals(date2)); 
  • A. false
  • B. true
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


D.

Note

February has 28 or 29 days, depending on the year.

There is never a February 31.

Java throws a DateTimeException when you try to create an invalid date, making Option D correct.




PreviousNext

Related