public class Point {
private int x, y;
public Point(int a, int b) { x = a; y = b; }
public String toString() {
return "(" + x + "," + y + ")";
}
}
// Usage:
Point p = new Point(3, 4);
System.out.print(p);What is printed?
- A
Point@hashcode
- B
3 4
- C
Compile error
- Dcheck_circle
(3,4)
Explanation
System.out.print on an object calls toString(). The overridden toString returns "(3,4)".