Object toString() in Java

toString(): This method is available in java.lang.Object class of Java.

Syntax:

String java.lang.Object.toString()

This method returns a string representation of the object.

In general, the toString method returns a string that"textually represents" this object. The result should be a concise but informative representation that is easy for a person to read.

It is recommended that all subclasses override this method.

Parameters: NA

Returns: a string representation of the object.

Exceptions: NA 

Approach

Java

public class ObjecttoString {
    public static void main(String[] args) {

        Object object = new Object();

        System.out.println(object.toString());
    }
}

Output:

java.lang.Object@182decdb


Some other methods of Object Class.

equals()This method indicates whether some other object is "equal to" this one.

hashCode()This method returns a hash code value for the object.

getClass()The returned Class object is the object that is locked by static synchronized methods of the represented class.


No comments:

Post a Comment