A Point Class Whose Object Represents a 2-D Point - Java Object Oriented Design

Java examples for Object Oriented Design:Class

Description

A Point Class Whose Object Represents a 2-D Point

Demo Code

class Point {
  private int x;
  private int y;

  public Point(int x, int y) {
    this.x = x;//from  ww w  .  j  a va 2  s  . c  om
    this.y = y;
  }

  // Re-implement toString() method of the Object class
  public String toString() {
    String str = "(" + x + ", " + y + ")";
    return str; 
  }
}

Related Tutorials