Java record-22-Explanation of basic class objects in Java
For details about the basic class objects of Java, you should refer to and use the JDK documentation frequently. It is best to view the documentation in English. Oracle official online Java API Specificationshttp: // www.oracle.com/technetwork/java/api-141528.html java. lang. Object class. The java. lang package does not need to be explicitly imported when it is used. during compilation, the compiler will automatically help us import data. Application Programinga Interface. Object obj = new Object (); System. out. println (obj); System. out. println (obj. toString (); the two printed content are the same. When a reference is printed, the return value of the toString () method that references the Object is actually printed, because each class inherits directly or indirectly from the Object, the Object class defines toString (), so each class has the toString () method. String str = "aaa"; System. out. println (str); System. out. println (str. toString (); both outputs are aaa. According to the above understanding, Sting must overwrite the toString () method of the Object. When a referenced Object is printed, the following code is displayed: java. lang. Object @ c17164. Why is such a string printed? You can view the toString () method of the Object class. Public String toString () Returns a string representation of the object. in general, the toString method returns a string that "textually represents" this object. the result shocould 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 class Object returns a string consisting of the name of 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 () Returns: a string representation of the object. java. lang. object @ c17164 class name + @ + address hexadecimal Representation 6. about the hexadecimal representation, in hexadecimal notation, a hexadecimal number includes: 0 ~ 9, A, B, C, D, E, F