class Student{
//学号
int no;
//学校
String school;
public Student() {
}
public Student(int no, String school) {
super();
this.no = no;
this.school = school;
}
//重写toString
public String toString() {
return "Student [学号" + no + ", 所在学校名字" + school + "]";
}
//当一个学生学号和学校相同时,表示同一个学生
public boolean equals(Object obj) {
if(obj = null || !(obj instanceof Student)) return false;
if(this == obj) return ture;
Student s = (Student)obj;
return this.no = s.no && this.school.equals(s.school);
}
}
public boolean equals(Object obj) {
if(obj = null || !(obj instanceof Student)) return false;
//是true而不是ture
if(this == obj) return ture;
Student s = (Student)obj;
//基本数据类型相等使用的是==判断,而不是=
return this.no = s.no && this.school.equals(s.school);
}
//当一个学生学号和学校相同时,表示同一个学生
public boolean equals(Object obj) {
if(obj == null || !(obj instanceof Student)) return false;
if(this == obj) return true;
Student s = (Student)obj;
return this.no == s.no && this.school.equals(s.school);
}
还是没办法解决object不能被强转,那我要怎么继续写下面的东西