← 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());
}
}
- A.150 150
- B.100 100
- C.150 100
- 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 →