Object obj = new Object();
Object obj1 = new Object();
int i = obj.hashCode();
System.out.println(i);
Class<?> Class1 = obj.getClass();
System.out.println(Class1);
String s = obj.toString();
System.out.println(s);
boolean eq = obj.equals(obj1);
System.out.println(eq);
public class TestDemo4 {
private int id;
private String name;
private int score;
public TestDemo4() {
}
public TestDemo4(int id, String name, int score) {
this.id = id;
this.name = name;
this.score = score;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
@Override
public String toString() {
return "TestDemo4{" +
"id=" + id +
", name='" + name + '\'' +
", score=" + score +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TestDemo4 testDemo4 = (TestDemo4) o;
return id == testDemo4.id && score == testDemo4.score && name.equals(testDemo4.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name, score);
}
}
TestDemo4 s1 = new TestDemo4(1,"欧阳修",66);
System.out.println(s1);
TestDemo4 s2 = new TestDemo4(1, "欧阳修", 63);
boolean eq = s1.equals(s2);
System.out.println(eq);