1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 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?

Show Answer
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

5 comments
Sign in to comment
thetechOption: A
Dec 2, 2019

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

steefaandOption: A
Feb 8, 2024

A is true without exception part.

iSnoverOption: C
Feb 8, 2024

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
Feb 10, 2024

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: A
Feb 10, 2024

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.

DarGrinOption: C
Jun 8, 2024

2016-02-14

DarGrin
Jun 8, 2024

answer is A