public class FifthTest12 {
public static void main(String[] args) {
Student01 s1=new Student01(666,"北京朝阳");
Student01 s2=new Student01(666,"北京朝阳");
System.out.println(s1==s2);
System.out.println(s1.equals(s2));
}
}
import java.util.Objects;
public class Student01 {
int no;
String school;
public Student01() {
}
public Student01(int no,String school) {
this.no = no;
this.school=school;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
@Override
public String toString() {
return "Student01{" +
"no=" + no +
", school='" + school + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Student01 student01 = (Student01) o;
return no == student01.no &&
Objects.equals(school, student01.school);
}
}