just learning Java and I know this may sound stupid but I have to ask.
System.out.print(new Date());
I know that whatever is in the argument is converted to a string, the end value that is,
new Date() returns a reference to a Date object. So how is it that it prints this?
Mon Aug 29 13:22:03 BST 2011
The only thing I can think of is somehow the function parses through all the data members gets their values converts them to a String and prints them.
If not how does it work?
Thanks
When you print something, the
toString()method of that object is called. So it is up to the individual class to provide an implementation that makes sense.For reference, see
And this is Date’s toString() method: