标题: 帮我看看这道题,急求答案,解释。 [打印本页] 作者: onlyonewf 时间: 2012-6-10 10:47 标题: 帮我看看这道题,急求答案,解释。 1. public class Test {
2. public <T extends Comparable> T findLarger(T x, T y) {
3. if(x.compareTo(y) > 0) {
4. return x;
5. } else {
6. return y;
7. }
8. }
9. }
and:
22. Test t = new Test();
23. // insert code here
Which two will compile without errors when inserted at line 23?
(Choose two.)
A. Object x = t.findLarger(123, “456”);
B. int x = t.findLarger(123, new Double(456));
C. int x = t.findLarger(123, new Integer(456));
D. int x = (int) t.findLarger(new Double(123), new Double(456)); 作者: 姚玉鹏 时间: 2012-6-10 13:05
Object x = t.findLarger(123, "456");-----> 类型转换异常
int x = t.findLarger(123, new Double(456)); ;-----> 编译失败
int x = t.findLarger(123, new Integer(456)); ;-----> 456
int x = (int) t.findLarger(new Double(123), new Double(456));;-----> 编译失败