Java Reference
In-Depth Information
Figure 8
The Object Class Is the Superclass of Every Java Class
10.8.1 Overriding the toString Method
The toString method returns a string representation for each object. It is used
for debugging. For example,
Rectangle box = new Rectangle(5, 10, 20, 30);
String s = box.toString();
// Sets s to
Define the toString method to yield a string that describes the object state.
In fact, this toString method is called whenever you concatenate a string with an
object. Consider the concatenation
Ðbox=Ñ + box;
On one side of the + concatenation operator is a string, but on the other side is an
object reference. The Java compiler automatically invokes the toString method
Search WWH ::

Custom Search