标签:java
==class B {
private int num;
B() {
num = 1;
}
}
B a = new B();
B b = new B();
System.out.println(a.equals(b));//false
String str_a = new String("abc");
String str_b = new String("abc");
System.out.println(str_a.equals(str_b)); //true
System.out.println(str_a==str_b); // false
StringBuffer sb1 = new StringBuffer("a");
StringBuffer sb2 = new StringBuffer("a");
System.out.println(sb1.equals(sb2)); //false
System.out.println(sb1==sb2); // false
class A {
private int a;
A() {
a = 1;
}
public boolean equals(A b) {
if (a == b.a)
return true;
else
return false;
}
}
A a = new A();
A b = new A();
System.out.println(a.equals(b)); //true
System.out.println(a == b); //false
标签:java
原文地址:http://blog.csdn.net/youxin2012/article/details/42877061