The purpose of the toString() method is to provide a string representation of an object's state. : toString method « Utility Classes « SCJP






public class MainClass {
  public static void main(String[] argv) {
    MyClass my = new MyClass();
    System.out.println(my.toString());
  }
}

class MyClass {

  public String toString() {
    return "MyClass";
  }
}
MyClass








8.3.toString method
8.3.1.The purpose of the toString() method is to provide a string representation of an object's state.
8.3.2.Override the toString() method in your classes