标签:
public class Worker { private int id; private String name; private double salary; public boolean equals(Object o){ boolean result = false; if(o== null){ result = false; }else{ if( o instanceof Worker) { Worker temp = (Worker) o; if(id == temp.id && name.equals(temp.name)){ result = true; }else{ result = false; } }else{ result = false; } } return result; } public String toString(){ return id+name; } }
一个Woker类,当id和name相同时,系统判断两个工人是相等的,打印工人对象时显示“工人:id和name”。
标签:
原文地址:http://www.cnblogs.com/xuhuaiqu/p/4552775.html