Question 7
Back to Exercise
What is the output of the following Java program?
record Money(String currency, long paise) { }
public class Main {
public static void main(String[] args) {
Money a = new Money("INR", 5000), b = new Money("INR", 5000), c = new Money("USD", 5000);
System.out.println(a + " " + (a == b) + " " + a.equals(b) + " " + a.equals(c) + " " + a.paise() / 100);
}
}
- A Money[currency=INR, paise=5000] false true false 50 Correct
- B Money@1b6d false false false 50
- C Money[INR, 5000] false true false 50
- D Money[currency=INR, paise=5000] true true false 50
Correct Answer: Option A
Records compare by components, not identity, and print as Name[comp=value, …].
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!