Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
2 成员方法
public int hashCode()
public final Class getClass()
public String toString()
public boolean equals(Object obj)
protected void finalize()
protected Object clone()
本小节讲解方法hashCode()和getClass()
3 public int hashCode()
暂时当作对象的地址
4 public final Class getClass()
可以看出,返回此 Object 的运行时类。
这里的Class是一个类,该类中有一个public string getName()方法
该类以 String 的形式返回此 Class 对象所表示的实体(类、接口、数组类、基本类型或 void)名称。
5 代码实现:
publicclass StudentDemo {
publicstaticvoidmain(String[] args) {
Student s1 = new Student();
System.out.println(s1.hashCode());// 57410271
Student s2 = new Student();
System.out.println(s2.hashCode());// 674267194
Student s3 = s1;
System.out.println(s3.hashCode());// 57410271
Student s = new Student();
System.out.println(s.getClass());// class xsh_itcast_02.Student
System.out.println(s.getClass().getName());// xsh_itcast_02.Student
}
}