class Employee{
private String name;
private int rollno;
public Employee(String name,int rollno)
{
this.name=name;
this.rollno=rollno;
}
}
public class CT2{
public static void main(String[]args){
Employee emp1 = new Employee("Raghu",35);
Employee emp2 = new Employee("Raghu",35);
Employee emp3 = new Employee("Raghu",35);
if(emp2.equals(emp3))
System.out.println("They are equal");
else
System.out.println("They are not equal");
}
}
上述代码有什么问题?理想情况下,它应该打印出"They are equal",但我得到的输出是"They are not equal"。
==
,而且如果他这样做了,OP的代码也不会起作用。 - Andy Turner