OCP Question 30, Explanation

Given the code fragment:

LocalDate javaBirthday = LocalDate.of(1995, Month.MAY, 23);
LocalDate twentiethAnniversary = javaBirthday.plusYears(20);
twentiethAnniversary.plusDays(1);                             //line n1
System.out.println(twentiethAnniversary);

What is the result?

A. 2015-05-23
B. A DateTimeException is thrown
C. 2015-05-24
D. A compilation error occurs at line n1

 

The correct answer is A.

Strange as it is, but a very similar question was also on the OCA exam. All you have to do is recall that every LDT-related class is immutable.

Leave Comment

Your email address will not be published. Required fields are marked *