← Unit 3 · all exercises
Saved in this browser only

A point on a grid

Write a Point class that stores an x and a y. Give it a constructor taking both, and getX and getY methods that hand them back.

class Point { Point(int x, int y); int getX(); int getY(); }

Point.java
Loading editor…
Results

Examples

  • new Point(3, 4).getX() → 3
  • new Point(3, 4).getY() → 4

There are also 3 hidden tests you can't see. Solve the problem, not the examples.