Java SE 8 Programmer II — Question 148

Given the code fragment:
LocalDate valentinesDay =LocalDate.of(2015, Month.FEBRUARY, 14);
LocalDate nextYear = valentinesDay.plusYears(1);
nextYear.plusDays(15); //line n1
System.out.println(nextYear);
What is the result?

Answer options

Correct answer: A

Explanation

The correct answer is A because the plusDays(15) method call does not modify the nextYear variable, which still references February 14, 2016. The other options are incorrect because no exception is thrown, no compilation error occurs, and February 29, 2016, is not the date referenced by nextYear.