Abid Ramay wrote:
public String toString()
public means that the method is visible and can be called from other objects of other types.
String tells you that the method's return type (output) is a String. The empty parenthesis in
toString() tell you that you don't have to pass in anything to the method.
Abid Ramay wrote:
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object.
This is the summary of the method's function. This also tells you that the toString() can be used on any object (since it is defined in the Object class).
The best way to find out exactly how a method works, however, is to try it out.
Try something like:
And try different things. For example, using the toString method on objects like Integer or Boolean simply returns their values as a String.