package cn.china; /**hashCode()方法默认是native方法,调用系统代码返回的是地址值; * 一般重写equals方法后,都需要调用hashCode方法,确保hash值相同来判断是同一个对象;*/ class Animals{ int age; public int hashCode(){ return age=60; } } public class HashDemo { public static void main(String[] args) { Animals animals=new Animals(); System.out.println(Integer.toHexString(animals.hashCode())); System.out.println(animals); } }