🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Date and Time in Java: all 10 questions

Quiz: Date and Time in Java · Question 3 of 10

What does this print? (code)

What does this print?

import java.time.*;
public class Main {
    public static void main(String[] args) {
        System.out.println(LocalDate.of(2026, 3, 31).plusMonths(1));
    }
}
  1. A.2026-05-01
  2. B.2026-04-31
  3. C.It throws DateTimeException
  4. D.2026-04-30
Answer & explanation

Correct answer: 2026-04-30

April has 30 days, so plusMonths moves to the last valid day of April.

Can you get the rest right without peeking?

Take the timed Quiz: Date and Time in Java quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →