Please don't call a class "string" because there is already a String class and you can get no end of confusion between the two. I have altered your indentation and added code tags (as somebody suggested) so you can see how much better the code looks. Please get a decent text editor (Google for NotePad2 and NotePad++) and use that; it is a lot better for coding that NotePad. Set the options to "replace tabs with spaces" and "tab setting = 4 spaces" which gives better indentation for Java. Always use thread headings which tell us what the thread is about.
Now to the question you are actually asking. Ankit Garg is probably correct in his link; I shall give you some more links.
You need to know how System.out.println() works and what it does, so you need to look in the API for System, then near the top there is a box with "field summary" written on, and you find "out" in there, with something like standard output stream against it. To the left of "out" it says "PrintStream;" click on that, then find the println method (click on "METHOD" at the top if you have any difficulty), then the version of println called println(Object x). Click on that, and it will give you the explanation. You may need this link as you explore through the API documentation.
Once you have been through all that, you should know what is happening. If not, please ask again.
Joined: Jan 19, 2009
Hi, I am student of MSc IT.
I want to know that how toString method is called automatically
when I Print the object.Please give me detail of toString method.