确认,你的结论是对的,此题无答案。D、E为false的原因如下:Integer.equals()
The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.Double.equals()
The result is true if and only if the argument is not null and is a Double object that represents a double that has the identical bit pattern to the bit pattern of the double represented by this object.
The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.Double.equals()
The result is true if and only if the argument is not null and is a Double object that represents a double that has the identical bit pattern to the bit pattern of the double represented by this object.
!!!!!!!!!!
大家都回答错了。一。a,b,c有会编译错误,因为i,l,d都是对象的实例,不用==判断他们是否
相等,==只能用于int,char,double等值的相等,不能判断对象的相等
二。object.equals()用来判断两个对象的相等,返回一个boolean值。
用于对象的判断,但是i是对象Integer的实例,l是Long的实例,d是Double的
实例,他们肯定是不相等的。
String b=a;
String c=new String("string");
a==b //true
a==c //false
b==c //false
a.equals(b) //true
a.equals(c) //true
b.equals(c) //true
所以==可以认为是地址的比较,而equals()可以看出是对象中的内容的比较。
String b=a;
String c=new String("string");
a==b //true
a==c //false
b==c //false
a.equals(b) //true
a.equals(c) //true
b.equals(c) //true
所以==可以认为是地址的比较,而equals()可以看出是对象中的内容的比较。
import java.applet.*;Integer i = new Integer (42);
Long l = new Long (42);
Double d = new Double (42.0);
public class New extends Applet {
public void init() {
} public void paint(Graphics g) {
g.drawString("Welcome to Java!!", 50, 60 );
g.drawString("A:="+(i==l),60,60);
g.drawString("B:="+(i==d),70,60);
g.drawString("C:="+(l==d),80,60);
g.drawString("e:="+(d.equals(i)),50,70);
g.drawString("d:="+(i.equals(d)),50,80);
g.drawString("F:="+(i.equals(42)),110,60);
}
}编译结果如下 :
--------------------Configuration: ques - j2sdk1.4.0 <Default>--------------------
I:\exeJ++\ques\Ques.java:17: incomparable types: java.lang.Integer and java.lang.Long
g.drawString("A:="+(i==l),60,60);
^
I:\exeJ++\ques\Ques.java:18: incomparable types: java.lang.Integer and java.lang.Double
g.drawString("B:="+(i==d),70,60);
^
I:\exeJ++\ques\Ques.java:19: incomparable types: java.lang.Long and java.lang.Double
g.drawString("C:="+(l==d),80,60);
^
I:\exeJ++\ques\Ques.java:22: cannot resolve symbol
symbol : method equals (int)
location: class java.lang.Integer
g.drawString("F:="+(i.equals(42)),110,60);
^
4 errorsProcess completed.