public class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() { return x; }
public int getY() { return y; }
}
// ...
Point p = new Point(4, 7);
System.out.println(p.getX() + "," + p.getY());What is printed?
- A
Compile-time error
- B
7,4
- C
0,0
- Dcheck_circle
4,7
Explanation
The constructor uses this.x = x and this.y = y to assign instance variables, so getX returns 4 and getY returns 7.