🎙 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 8 of 10

What does this print? (code)

What does this print?

record Money(long paise) {
    Money plus(Money o) { return new Money(paise + o.paise); }
}

public class Main {
    public static void main(String[] args) {
        Money a = new Money(100);
        Money b = a.plus(new Money(50));
        System.out.println(a.paise() + " " + b.paise());
    }
}
  1. A.150 150
  2. B.100 100
  3. C.150 100
  4. D.100 150
Answer & explanation

Correct answer: 100 150

plus returns a new object; a keeps its original value.

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 →