一、需求
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/303f4d7691d622a93cd0f99a1d7ac79b.jpeg)
二、实现
1.学生类Student
package com.eleven.csdn1226;
public class Student {
private Integer studentID;
private String name;
private Float score;
public Integer getStudentID() {
return studentID;
}
public void setStudentID(Integer studentID) {
this.studentID = studentID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Float getScore() {
return score;
}
public void setScore(Float score) {
this.score = score;
}
public boolean equals(Object obj) {
if (obj.equals(studentID)) {
return true;
} else {
return false;
}
}
}
2.测试类StudentTest
package com.eleven.csdn1226;
public class StudentTest {
public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student();
s1.setStudentID(123);
s2.setStudentID(123);
System.out.println(s1.equals(s2));
}
}
3.运行输出
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/176783bec282f32f6ff9333a36d4d9c5.png)