Re: question about the toString Method



On Thu, 27 Dec 2007 12:46:52 -0500, "Art Cummings"
<aikiart7@xxxxxxxxx> wrote, quoted or indirectly quoted someone who
said :

System.out.println(myCourse); **************WHY DOES THIS CALL THE
toString method in the Class course?****************

Have a look at how println is implemented. Look in src.zip.

In essence it looks something like this

void println ( Object o )
{
// the console needs a string of chars. I just have an object
// so I will call the the toString method which every object has
// or overrides.
sendToConsole ( o.toString() );
println();
}

Why? How else would you get a String to print?
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.


Quantcast