/**来 自 n o w j a v a . c o m**/
public class TestEquality2
{
public static void main(String[] args)
{
Employee emp1 = new Employee("M", "A");
Employee emp2 = new Employee("M", "A");
if (emp1.equals(emp2))
System.out.println("These employees are the same.");
else
System.out.println("These are two different employees.");
}
}
class Employee
{
private String lastName;
private String firstName;
public Employee(String lastName, String firstName)
{
this.lastName = lastName;
/**
来自 时代Java - N o w J a v a . c o m**/
this.firstName = firstName;
}
public String getLastName()
{
return this.lastName;
}
public String getFirstName()
{
return this.firstName;
}
public boolean equals(Object obj)
{
// an object must equal itself
if (this == obj)
return true;
// no object equals null
if (this == null)
return false;
// objects of different types are never equal
if (this.getClass() != obj.getClass())
return false;
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。