Java Basics Hardening The Hashcode () method, GetClass () method of the 27:object class

Source: Internet
Author: User

1. The Hashcode () method of the object class is as follows:

public int hashcode (): Returns the hash code value of the object, which is related to the address value, but not the actual address value (the hash value is an integer value converted from the actual address value), which you can interpret as the address value.

2. The GetClass () method of the object class is as follows:

Public final Class getclass (): returns the run-time class for this object (the returned type is class, which actually returns the object entity of Class)

Method of Class:

Public string getName (): Returns the entity represented by this Class object as a string

3. Case studies

(1) Student class

1  Package cn.itcast_01; 2 3  Public class extends Object {45 }

(2) Studenttest class

1  Packagecn.itcast_01;2 3 /*4 * Object: Class object is the root class of a class hierarchy. Each class uses Object as a superclass. 5 * Each class is inherited directly or indirectly from the object class. 6  * 7 * Method of the object class:8 * public int hashcode (): Returns the hash code value of the object. 9 * Note: The hash value is a value computed from the hash algorithm, which is related to the address value, but not the actual address value. Ten * You can understand the value of the address.  One  *  A * Public final Class GetClass (): Returns the run-time class for this Object - * Method of class: - * public String GetName (): Returns the entity represented by this Class object as a string the  */ -  Public classStudenttest { -      Public Static voidMain (string[] args) { -Student S1 =NewStudent (); +System.out.println (S1.hashcode ());//11299397 -Student s2 =NewStudent (); +System.out.println (S2.hashcode ());//24446859 AStudent s3 =S1; atSystem.out.println (S3.hashcode ());//11299397 -System.out.println ("-----------"); -  -Student s =NewStudent (); -Class C =S.getclass (); -String str =c.getname (); inSystem.out.println (str);//Cn.itcast_01.Student (package name + class name)---full path name -          to         //Chained Programming +String str2 =S.getclass (). GetName (); - System.out.println (str2); the     } *}

Java Basics Hardening The Hashcode () method, GetClass () method of the 27:object class

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.