API Evolution · interview question
What will be the output of the following code? LocalDate date = LocalDate.of(2023, 2, 28); LocalDate newDate = date.plusDays(1); System.out.println(newDate);?
Multiple choiceMediumchapter-12-curatedpremiumapi-evolutionmodern-date-and-time
LocalDate date = LocalDate.of(2023, 2, 28);
LocalDate newDate = date.plusDays(1);
System.out.println(newDate);Answer and explanation
Correct answer
A. 2023-03-01
Why
Adding one day to February 28th, 2023 gives March 1st, 2023. The LocalDate.plusDays method correctly handles month transitions, including leap years.
Test yourself on API Evolution
A free test with instant, explained results. No account needed.
More API Evolution questions
- What does subtracting one month from March 31 using java.time.LocalDate evaluate to?
- How does java.time.Instant ensure thread safety?
- How would you calculate the number of days between two java.time.LocalDate objects?
- When comparing two Instant objects, which method would you use?
- What will be the result of comparing two ZonedDateTime objects from different time zones but representing the same…
- Which class would you use to represent a date without a time-zone in the java.time package?