Given this code snippet:
LocalDate dateOfBirth = LocalDate.of(1988, Month.NOVEMBER, 4); MonthDay monthDay = MonthDay.of(dateOfBirth.getMonth(), dateOfBirth.getDayOfMonth()); boolean ifTodayBirthday = monthDay.equals(MonthDay.from(LocalDate.now())); // COMPARE System.out.println(ifTodayBirthday ? "Happy birthday!" : "Yet another day!");
Assume that today's date is 4th November 2015.
Choose the correct answer based on this code segment.
c)
this code gets the month-and-day components from the given LocalDate and creates a MonthDay object.
another way to create a MonthDay object is to call the from()
method and pass a LocalDate object.
the equals()
method compares if the month and date components are equal and if so returns true.
Since the month and day components are equal in this code (assuming that the today's date is 4th November 2015 as given in the question), it results in printing "Happy birthday!".