Object: toString() : Object « java.lang « Java by API






Object: toString()

 
/*
 * Output:
 * Point[123456789,2147483647]
 * */

class Point {
  int x, y;

  Point(int x, int y) {
    this.x = x;
    this.y = y;
  }

  public String toString() {
    return "Point[" + x + "," + y + "]";
  }

}

public class MainClass {
  public static void main(String args[]) {
    Point p = new Point(123456789, 2147483647);
    System.out.print(p);
  }
}
           
         
  








Related examples in the same category

1.Object: finalize()
2.Object: getClass()
3.Object: getClass() (2)
4.Object: hashCode()
5.Object: notifyAll()
6.Object: wait(long timeout)