as String concatenation triggers the call to toString() of Box.
Yes, it's one of the automagic shortcuts that the people who designed Java created. If you concatenate a String with something else, the toString() method of the something else is automatically called. It works with primitives (even though primitives don't really have a toString method per se) as well as with objects.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
How does the method public String toString() in class Box get called, if we have not explicitly stated it should If you call System.out.println(box), the "toString()" method will also be called. This happens to be a nice mechanism for debugging purposes, as you can print the state of the object at run time when diagnosing the problem. So overriding the "toString" method of your classes is always a good idea.