Java OCA OCP Practice Question 2245

Question

Choose the correct option based on this code segment:

LocalDate babyDOB = LocalDate.of(2015, Month.FEBRUARY, 20);
LocalDate now = LocalDate.of(2016, Month.APRIL, 10);
System.out.println(Period.between(now, babyDOB).getYears()); // PERIOD_CALC
  • A. the code segment results in a compiler error in the line marked with the comment PERIOD_CALC
  • B. the code segment throws a DateTimeException
  • C. the code segment prints: 1
  • D. the code segment prints: -1


D.

Note

here are the arguments to the between() method in the Period class:

Period between(LocalDate startDateInclusive, LocalDate endDateExclusive)

the first argument is the start and the second argument is the end, and hence the call Period.between(now,babyDOB) results in -1 (not +1).




PreviousNext

Related