FileDocCategorySizeDatePackage
Point.javaAPI DocExample431Wed Apr 20 14:43:54 BST 2005None

Point.java

/** Represents a Cartesian (x,y) point */
public class Point {
     public double x, y;                    // The coordinates of the point
     public Point(double x, double y) {     // A constructor that
         this.x = x; this.y = y;            // initializes the fields
     }

     public double distanceFromOrigin() {   // A method that operates on
         return Math.sqrt(x*x + y*y);       // the x and y fields
     }
}