What is the result?

Given the code fragment:

What is the result?
A. 2012-02-10 00:00
B. 2012-01-30
C. 2012-02-10
D. A DateTimeException is thrown at runtime.

Download Printable PDF. VALID exam to help you PASS.

6 thoughts on “What is the result?

  1. -LocalDate is immutable, so in order to update the “date” object we would have to do this instead “date = datePlusDays(10);”
    -Doing datePlusDays(10) on its own does absolutely nothing to the date object
    -Keep an eye out for this trick on dates and Strings
    -FUN FACT: Calling a method this way on StringBuilder would actually change its value

  2. Answer B. It will print the same value of the “date” (i.e. without changes), this is because LocalDate objects are immutable, accordingly, any changes to any immutable object creates a new object. In addition, the line (date.plusDays(10) ) indeed increases the dates by 10. But however, the value of ( date.plusDays(10) ) has been ignored and not saved to the reference variable (date). Accordingly, no changes has been made to the value of the original (date) reference variable.
    So, in order to get the new result, you should replace the line ( date.plusDays(10) ) by: date = date.plusDays(10);

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.