Java每日一题20170104

20170103问题解析请点击今日问题下方的“【Java每日一题】20170104”查看(问题解析在公众号首发,公众号ID:weknow619)

package Jan2017;

import java.util.HashSet;
import java.util.Set;

public class Ques0104{
    
    public static void main(String[] args){
        Obj obj01 = new Obj("张三");
        Obj obj02 = new Obj("李四");
        Obj obj03 = new Obj("李四");
        
        Set set = new HashSet();
        set.add(obj01); 
        set.add(obj02); 
        set.add(obj03); 
        System.out.println(set.size());
    }
}
    
class Obj{
    private String id;
    
    public Obj(String id){
        this.id = id;
    }
    
    @Override
    public int hashCode(){
        return 123;
    }
    
    @Override
    public boolean equals(Object obj){
        if (this == obj){
            return true;
        }
        
        if (obj instanceof Obj && this.id.equals(((Obj) obj).id)){
            return true;
        }
        return false;
    }
}

今日问题:
请问主程序输出结果是什么?(点击以下“【Java每日一题】20170104”查看20170103问题解析)

你可能感兴趣的:(Java每日一题20170104)