Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 66

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?

    Correct Answer: A

    The given code creates a LocalDate object representing February 14, 2015, then increments it by one year to get a new LocalDate object representing February 14, 2016. The method call nextYear.plusDays(15) generates a new object but doesn't reassign the new object back to a variable, because LocalDate is immutable. Therefore, nextYear remains February 14, 2016, and the output is 2016-02-14.

Discussion
Tarik2190Option: A

Answer is A because of immutable nature, to get C it should be: nextYear = nextYear.plusDays(15);

aymanjOption: A

Answer is A .. LocalDate is immutable

asdfjhfgjuaDCVOption: A

A is the correct answer

steefaandOption: A

A is correct. Date and time classes are immutable so nextYear.plusDays(15); //line n1 is ignored since it is not assigned to variable.

WilsonKKerllOption: A

Answer is A.