Forums Register Login

toString()

+Pie Number of slices to send: Send
Hai,
When we print the object of the class like System.out.print(new Class()) default constructor of that class
will be called.. And toString() method also will be called.. Can anyone explain me what s reason behind tat??
1
+Pie Number of slices to send: Send
It's that way by design:


public void print(Object obj)
Prints an object. The string produced by the String.valueOf(Object) method is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


PrintWriter.print()
How else would you convert an Object to a printable representation?
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 716 times.
Similar Threads
Method Exception declaration when inheritance.
doubt in the advance for loop in java6
constructor question
confused with use of " this" in the constructor
NullPointerException
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:50:54.