File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String" Watch "String" New topic


cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
Dear all,
I submit you something I find quite intersting, about String, toString, ...

As you may expect, the result is something of the following form:
Indeed, System.out.println invokes automatically the toString() method inherited from Object on instance Z, which prints out the name of the object's class + some identifying value - typically its reference value, separated by iy the at symbol.
What's happening now with this code?

Waht is worth noting here is that "Z" is printed out on its own line before the toString() method would be happened to AAA on its own line also.
The same logic applies in the following case, when overriding the toString method:

Hoe this can help,

SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
Indeed, and this is beacuse first the operands are evaluated (BOTH of them) and then the operations is completed. In Both examples evaluating the right operand, means to print "Z" or "###".

Miki<br /> <br />SCJP 1.4, SCBCD 1.3
I agree. Here's the link:
subject: String
jQuery in Action, 3rd edition