We can use toString() method to get String representation of an Object.
Whenever we are trying to print any object reference then internally toString() method will be executed.
In java.lang package Object class contains toString() method as non-final method.
The toString() method of Object class returns ClassName@hashCodeInHexadecimalNotation.
As Object class is super class for every method so it is inherited into every java class.
The toString method is non-final method every class can override this method.
Whenever we are displaying a ref on the monitor using println() or print() methods and if the reference is not pointing null then these methods internally call toString() on the ref and prints the result of toString().
If reference is pointing null then NullPointerException is not generated only null is printed.
If our class is overriding toString() then our class toString() return value is printed.
If our class is not overriding toString() then Object class toString() return value is printed i.e., ClassName@hashCodeInHexadecimalNotation.