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

Quiz: Records and Sealed Classes · Question 1 of 10

What does this print? (code)

What does this print?

record Point(int x, int y) { }
public class Main {
    public static void main(String[] args) {
        Point p = new Point(3, 4);
        System.out.println(p);
    }
}
  1. A.Point@1b6d3586
  2. B.(3, 4)
  3. C.Point[x=3, y=4]
  4. D.Point{x=3, y=4}
Answer & explanation

Correct answer: Point[x=3, y=4]

The generated toString prints the record name and each component in square brackets.

Can you get the rest right without peeking?

Take the timed Quiz: Records and Sealed Classes quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →