What is the result of the following?
11: LocalDate myBirtiday = LocalDate.of(2017, Month.MARCH, 25);
12: Period period = Period.of(1, 6, 3);
13: LocalDate later = myBirtiday.plus(period);
14: later.plusDays(1);
15: LocalDate thisOne = LocalDate.of(2018, Month.SEPTEMBER, 28);
16: LocalDate thatOne = LocalDate.of(2018, Month.SEPTEMBER, 29);
17: System.out.println(later.isBefore(thisOne) + " "
18: + later.isBefore(thatOne));
B.
Line 12 creates a Period representing a year, six months, and three days.
Adding this to myBirtiday
gives us the year 2018, the month of September, and a day of 28.
This new date is stored in later on line 13 and represents September 28, 2018.
Line 14 has no effect as the return value is ignored.
Line 17 checks that you know that isBefore()
returns false if the value is an exact match.
Since thisOne
is an exact match but thatOne
is a whole day before, the output is false true, making Option B correct.