← Quiz: Immutability and Value Objects: all 10 questions
Quiz: Immutability and Value Objects · Question 5 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 a = new Point(1, 2);
Point b = new Point(1, 2);
System.out.println((a == b) + " " + a.equals(b));
}
}
- A.true true
- B.false true
- C.false false
- D.true false
Answer & explanation
Correct answer: false true
They are two different objects (== is false), but records compare by value (equals is true).
Can you get the rest right without peeking?
Take the timed Quiz: Immutability and Value Objects quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →