// Since every class in Java is a subclass of class $Object$, you may // use methods inherited from $Object$. // One such method, $toString$, provides a good way of returning a string // representation of the object. If you print the inherited version // from $Object$, you will see the object's address. Note that // printing an object's reference causes Java to automatically call // that object's $toString$ method. public class object1 { public static void main(String[] args) { A a = new A(); System.out.println("Print the ref from MC: " + a); System.out.println("Print with $toString$: " + a.toString()); } } class A { A() { System.out.println("Print with $toString$ from `within' the " + "object: " + this.toString() ); } } /* Output: Print with $toString$ from `within' the object: A@1dacd404 Print the ref from MC: A@1dacd404 Print with $toString$: A@1dacd404 */