public class TestEquals {
public static void main(String[] args){
Student s1=new Student("我:","她");
Student s2=new Student("我:","她");
System.out.println(s1==s2);
System.out.println(s1.equal(s2));
System.out.println((s1.getMe())==((s2).getMe()));
}
}
class Student {
private String me;
private String you;
public Student(String me,String you){
this.me=me;
this.you=you;
System.out.println(me+you+"怎么不好好照顾自己?傻!");
}
public String getMe(){
return me;
}
s1对象和s2对象不是放在堆内存的两个不同地方吗?它们调用的"me"的存储地址相同吗?为什么调用"=="比较会返回true?
hwj3747
断桥1
相关分类