我有一个名为Student的类,其中包含两个变量name,no,并且我为该类创建了两个对象,现在我要检查两个对象是否相同。我正在使用.equals()方法,但没有得到正确的输出。
public class Student {
String name;
int no;
Student(String name,int no){
this.name=name;
this.no=no;
}
public static void main(String[] args) {
Student s1 = new Student("abc", 10);
Student s2 = new Student("abc", 10);
System.out.println(s1.equals(s2));
}
}
输出:false
答案 0 :(得分:2)