当前位置: 技术问答>java相关
scjp考题一道,请大家帮忙分析?
来源: 互联网 发布时间:2015-03-01
本文导语: Integer i = new Integer (42); Long 1 = new Long (42); Double d = new Double (42.0); Which two expressions evaluate to True? (Choose Two) A. (i ==1) B. (i == d) C. (d == 1) D. (i.equals (d)) E. (d.equals (i)) F. (i.equals (42)) 我选 c e 请...
Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);
Which two expressions evaluate to True? (Choose Two)
A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))
我选 c e 请大家帮忙分析?
Long 1 = new Long (42);
Double d = new Double (42.0);
Which two expressions evaluate to True? (Choose Two)
A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))
我选 c e 请大家帮忙分析?
|
不会吧?
i, l, d的类型不同,不能用==比较吧
F选项肯定不行,参数应该是Object,不能是42
D和E我编程验证了一下,好象都是false啊
i, l, d的类型不同,不能用==比较吧
F选项肯定不行,参数应该是Object,不能是42
D和E我编程验证了一下,好象都是false啊
|
全错啊,写个程序好了,那个家伙不要在这里骗人了!!!
temp.java:9: incomparable types: java.lang.Integer and java.lang.Long
System.out.println(i==l);
^
temp.java:10: incomparable types: java.lang.Integer and java.lang.Double
System.out.println(i==d);
^
temp.java:11: incomparable types: java.lang.Double and java.lang.Long
System.out.println((d==l));
^
temp.java:14: cannot resolve symbol
symbol : method equals (int)
location: class java.lang.Integer
System.out.println(i.equals(42));
^
4 errors
temp.java:9: incomparable types: java.lang.Integer and java.lang.Long
System.out.println(i==l);
^
temp.java:10: incomparable types: java.lang.Integer and java.lang.Double
System.out.println(i==d);
^
temp.java:11: incomparable types: java.lang.Double and java.lang.Long
System.out.println((d==l));
^
temp.java:14: cannot resolve symbol
symbol : method equals (int)
location: class java.lang.Integer
System.out.println(i.equals(42));
^
4 errors
|
其实,很奇怪,没有一个选项是对的。
|
我上当了!冤枉啊!哈哈哈哈哈
根本不能编译啊!哈哈哈哈哈
根本不能编译啊!哈哈哈哈哈