Java OCA OCP Practice Question 762

Question

What is the result of the following?

LocalDate xmas = LocalDate.of(2016,  12,  25); 
xmas.setYear(2020); 
System.out.println(xmas.getYear()); 
  • A. 2016
  • B. 2020
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

The Java 8 date and time classes are immutable.

This means they do not contain setter methods and the code does not compile.




PreviousNext

Related