You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Learn/Jb38_ObjClass.java

50 lines
905 B

public class Jb38_ObjClass
{
public static void main(String[] args)
{
Dog d1 = new Dog("daHei");
Dog d2 = new Dog("daHei");
Dog d3 = d1;
Demo d = new Demo();
System.out.println(d1==d2);
System.out.println(d1.equals(d2));
//System.out.println(d1.equals(d));
System.out.println(d1);
System.out.println(d1.hashCode());
Class c1 = d1.getClass();
Class c2 = d2.getClass();
System.out.println(c1==c2);
System.out.println(d1.getClass().getName());
}
}
class Dog extends Object
{
private String name;
Dog(String name)
{
this.name = name;
}
/*
һ<EFBFBD><EFBFBD><EFBFBD>Ǵ˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж϶<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
public boolean equals(Object obj)
{
if (!(obj instanceof Dog))
{
throw new ClassCastException("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>岻ͬ<E5B2BB><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
Dog d = (Dog)obj;
return this.name == d.name;
}
public String toString()
{
return "Dog:"+name;
}
}
class Demo
{
}