println(Object) calls toString() on the argument; this String is then displayed. See the Javadocs for java.lang.Object.toString() (which your class inherits, because it doesn't override this method) for a detailed explanation.
this usually invokes the current reference object.so when u try to print using the line
System.out.println(this);
u r trying to print the object reference using toString(). check out the sample ...
class trial { public static void main(String args[]) { trial obj=new trial(); System.out.println(obj); } }
u get output as trial@13e8d89
Hope this helps...
Regards,
Shafi.
Regards,<br /> <br />Shafi.
lalit upadheyay
Ranch Hand
Joined: Jun 20, 2005
Posts: 110
posted
0
what does "System.out.println(this);" do?
It implicitly invokes the toString() method for anything supplied to it as parameter ( whether primitive or object references ), here the current object reference . Since your class does not provide implementation of public String toString(Object o) method , it will inherit implemenattion from its parent class i.e. Object class, and will invoke it here.
Why it give trial42@107077e? If your class does not override the implementation of toString() method inherited by your class from the Object class ( grand dady of all classes ) then you will get class name here trial42 followed by hashCode() for the object. For details regarding these methods i would suggest you to refer to API documentation for Object class