Java tostring method

2022-06-05 0 By

The toString method, from the Object class, returns a string describing the current object.When we print an object using system.out.println (), the toString method is called to get a description of the current object.1. The toString method is defined in the Object class. Because every class in Java inherits the Object class by default, every class has a toString method that returns a string representation of the Object (class name + symbol @+ hash code of the Object).The toString method has been overridden by common classes such as String and Date to make the return value more meaningful.2. Public String toString() returns a String representation of this object.Normally, the toString method returns a string that “represents” the object as text.The result should be a concise yet easy to read.It is recommended that all subclasses override this method.The toString method of the Object class returns a string consisting of the class name, the AT marker “@”, and an unsigned hexadecimal representation of the Object’s hash code.Class Object is the core class of the Javajava.lang package. Class Object is the parent of all classes. Any class that does not explicitly inherit a parent is a subclass of Object.The Object class belongs to the java.lang package. All classes in this package do not need to be manually imported during program compilation