package practice;
/**
* Created by fangjiejie on 2016/12/4.
*/
public class BB {
int b1;
String b2;
public BB(int b1, String b2) {
this.b1 = b1;
this.b2 = b2;
}
public static void main(String[] args) {
BB a1=new BB(666,"hello");
BB a2=new BB(666,"hello");
System.out.println(a1==a2);
System.out.println(a1.equals(a2));
}
}
class EE{
int c1;
String c2;
public EE(String c2, int c1) {
this.c2 = c2;
this.c1 = c1;
}
@Override
public boolean equals(Object obj) {
if(this==obj){
return true;
}
if(obj==null){
return false;
}
if(this.getClass()!=obj.getClass()){
return false;
}
EE obje=(EE)obj;
return this.c1==obje.c1 && this.c2.compareTo(obje.c2)==0;
}
public static void main(String[] args) {
EE c1=new EE("hello",666);
EE c2=new EE("hello",666);
System.out.println(c1==c2);
System.out.println(c1.equals(c2));
EE c3=new FF("hello",666);
FF c4=new FF("hello",666);
FF c5=new FF("hello",666);
System.out.println(c1.equals(c3));
System.out.println(c3.equals(c4));
System.out.println(c4.equals(c5));
}
}
class FF extends EE{
FF(String c2, int c1){
super(c2,c1);
}
}