Java OCA OCP Practice Question 1816

Question

What does the following output?

int year = 2020; 
int month = Month.MARCH; 
int day = 24; 
LocalDate date = LocalDate.of(year, month, day); 
System.out.println(date.isBefore(LocalDate.now())); 
  • A. false
  • B. true
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

LocalDate allows passing the month as an int or Month enum parameter.

However, Month.MARCH is an enum.

It cannot be assigned to an int variable, so the declaration of month does not compile, and Option C is correct.




PreviousNext

Related