public class Pair {
private int a, b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
public int sum() { return a + b; }
}
// ...
Pair p = new Pair(3, 4);
System.out.println(p.sum());What is printed?
- Acheck_circle
7
- B
0
- C
12
- D
Compile-time error
Explanation
this.a and this.b are set to 3 and 4; sum returns 7.