public class Student {
private String name;
private int age;
public Student(String name, int age) {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class Application {标签:getClass,name,s2,s1,hashCode,age,Student,方法,public From: https://www.cnblogs.com/123456dh/p/17118780.html
public static void main(String[] args) {
Student s1 = new Student("a",18);
Student s2 = new Student("b",17);
//getClass方法
//判断s1和s2是不是同种类型
Class<? extends Student> Class1 = s1.getClass();
Class<? extends Student> Class2 = s2.getClass();
if(Class1==Class2){
System.out.println("s1和s2属于同种类型");
}else{
System.out.println("s1和s2不属于同种类型");
}
//s1和s2属于同种类型
//hashCode方法
System.out.println(s1.hashCode());//1324119927
System.out.println(s2.hashCode());//990368553
//s1和s2哈希值不同
}
}