1.Father
public String getHobby() {
return hobby;
}
public boolean compare(Father father){
if(this.getHobby().equals(father.getHobby())){
return true;
}else {
return false;
}
}
2.Test
Father father = new Father("抽烟");
Father father2 = new Father("抽烟");
// 重写之前对比的是对象的地址,重写之后对比的是对象的值
// false
System.out.println(father.equals(father2));
// true
System.out.println(father.compare(father2));
int i = 8;
int j = 8;
// true
System.out.println(i == j);
String s = "a";
String s1 = new String("a");
String s2 = new String("a");
// false
System.out.println(s == s1);
// true
System.out.println(s.equals(s2));