package javaBasic;
public class TestObject {
public static void main(String[] args) {
// TODO Auto-generated method stub
Person p = new Person(1,"诸葛亮");
System.out.println(p.getClass());
System.out.println(p.getClass().getName());
//获取对象的hash码
System.out.println(p.hashCode());
Person pa = new Person(2,"关羽");
System.out.println(pa.hashCode());
String sa = "诸葛亮";
String sb = "张三";
System.out.println(sa.hashCode() +" sb "+ sb.hashCode());
//toString方法
System.out.println("pa toString --" + pa.toString());
//输出对象的时候会自动调用对象的toString 方法
//toString 是该对象的hashCode()的十六进制 toHexString()
//如果不想使用父类的 toSting 方法,直接在子类中覆盖 toSting方法
System.out.println("pa--" + pa);
}
}
class Person{
int id;
String name;
public Person(int id, String name){
super();
this.id = id;
this.name = name;
}
//覆盖原来的toString方法
/*public String toString(){
return "id:" + id + ",name:" + name;
}*/
}