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?
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?
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`.
After running the program the result will be 2016-02-14
A is true without exception part.
2016-02-14
answer is 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.
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.
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.