🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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));
    }
}
  1. A.true true
  2. B.false true
  3. C.false false
  4. 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 →