← 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);
}
}
- A.Point@1b6d3586
- B.(3, 4)
- C.Point[x=3, y=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 →