Because that's what happens when you use the String concatenation operator (+
).
It calls the toString()
method of the object being added (which is guanateed to be there since it's defined in Object
).
In your case, that's the current object (this
) so you get this.toString()
called. And because you've overriden toString()
in your class, you get the result of that.
Edit to add: Note that there's no difference between + this
and + this.toString()
; you'll end up with the same result.
Specifically, this is covered by section 15.18.1 of the JLS
If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run time.
And §5.1.11 states:
...
Now only reference values need to be considered:
If the reference is null, it is converted to the string "null" (four ASCII characters n, u, l, l).
Otherwise, the conversion is performed as if by an invocation of the toString method of the referenced object with no arguments; but if the result of invoking the toString method is null, then the string "null" is used instead.