Java record-22-Explanation of basic class objects in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.