This is with the reference from my earlier blog. read the comment at the top before reference. | Techbirds

// to see the effect of override copy code and uncomment the override part. // hash code overriding will join you later.

public class Obj {

/** * @param args */ int value; Obj(int i) { this.value = i;

}

/*@Override public boolean equals(Object o) { Obj here=(Obj)o; if(this.value == here.value) return true; else if (o==null) return false; else

return false;

} */public static void main(String[] args) { // TODO Auto-generated method stub Object ob1=new Obj(5); Object ob2=new Obj(5); Object ob3=ob1; int hash= ob1.hashCode(); System.out.println(“hash code:”+hash); hash=ob2.hashCode(); System.out.println(“hash code now:”+hash); hash= ob3.hashCode(); System.out.println(“o3 reference=”+hash); if(ob1==(ob2)) System.out.println(“Equals objects”); else

System.out.println(“Unequal”);

if(ob1.equals(ob2)) System.out.println(“Equals objects”); else System.out.println(“Unequal”);

}

}

486 total views, 2 views today

Share this Onfacebook-2123681twitter-7041458linkedin-9342636google-4125737