// Point2D.java -- immutable two-dimensional double point

public final class Point2D {

   // "instance variables" or "member fields"
   final double x, y;

   // constructors
   Point2D ()                   { this (0.0, 0.0); }
   Point2D (final double x, final double y) { this.x=x; this.y=y; }

   // methods
   double distance (final Point2D p) {
      return Math.hypot (p.x-this.x, p.y-this.y);
   }

   // NB. "public" is necessary.
   @java.lang.Override // The annotation is highly recommended
   public String toString () {
      return String.format ("(%f,%f)", x, y);
   }
}