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

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: B

    The code initializes `valentinesDay` with the date February 14, 2015. Then, it creates `nextYear` by adding one year to `valentinesDay`, resulting in February 14, 2016. The statement `nextYear.plusDays(15)` does not affect the `nextYear` variable because `LocalDate` is immutable, and the result of `plusDays` is not stored in a new variable. Therefore, the output remains `2016-02-14`.

Discussion
thetechOption: A

After running the program the result will be 2016-02-14

steefaandOption: A

A is true without exception part.

DarGrinOption: C

2016-02-14

DarGrin

answer is A

iSnoverOption: A

I apologize for the wrong answer, there was a typo in the letter A which after the result would throw an Exception but the Exception part does not exist. What makes answer A correct. My other comment is wrong.

iSnoverOption: C

The answer is C, there is a similar question where the answer would be "2016-02-14" but there is no such answer, so the answer is "2016-02-29 line n1." which is true, the "nextYear" variable gains this value in line n1 but after it loses it because DateTime are immutable and another variable did not store the value.

iSnover

I apologize for the wrong answer, there was a typo in the letter A which after the result would throw an Exception but the Exception part does not exist. What makes answer A correct. My other comment is wrong.