Home » Java Object toString() Method with Examples

Java Object toString() Method with Examples

by Online Tutorials Library

Java Object toString() Method

toString() is the method of Object class. This method returns a string that is the representation of the object, which contain name of the class of which the object is an instance. The returned string is in the following form:-

getClass().getName() + ‘@’ + Integer.toHexString(hashCode())

Syntax

Returns

It return a string representation of the object.

Example 1

Test it Now

Output:

Example 2

Test it Now

Output:

Addition of 10 and 20 :   Answer : 30  [email protected]  

Next TopicJava Object Class

You may also like