What does java.lang.Object@19821f means ? This is the output when I try to print the variable of Object type without any Assignment. code:
Object object = new Object();
System.out.println(object);
What does java.lang.Object@19821f means ? This is the output when I try to print the variable of Object type without any Assignment. code:
Object object = new Object();
System.out.println(object);
RTFM, Object#toString
:
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.The
toString
method for classObject
returns a string consisting of the name of the class of which the object is an instance, the at-sign character '@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:getClass().getName() + '@' + Integer.toHexString(hashCode())
It's important to note that behind the scenes, System.out.println
invokes the toString
method of its argument.
It's just what the toString()
method outputs for the Object
type. It's (currently) specified to be:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Because Object
is the uber-class for all objects, it could be any type of object, so it's expected that derived objects will override the toString()
method to provide a more useful representation.
That's the default implementation of Object.toString()
. You can even look at the source code for it.
This is the hashcode of the Object that you just instantiated. the println method just calls the Objects toString method.