五.import java.util.*;
public class Car implements Comparator{
public int wheels = 0;public Car(){};
public Car(int wheels){
this.wheels = wheels;
}
public int compare (Object o1,Object o2){
Car c1 = (Car)o1;
Car c2 = (Car)o2;
return new Integer(c1.wheels).compareTo(new Integer(c2.wheels));}
public String toString(){ return new Integer(wheels).toString();
}
public static void main(String[] args){
Car c1 = new Car(1);
Car c2 = new Car(2);
Car c3 = new Car(3);
TreeSet list = new TreeSet(new Car());
list.add(c3);
list.add(c1);
list.add(c2);
Iterator it = list.iterator();
while (it.hasNext())
System.out.println(it.next()+"");
}
}
A) compilation succeds compare()throws classCastException;
B) compilation succeds.output is 0 1 2 3;C) compilation succeds.output is 1 2 3;D) compilation fails compare() methed does not have the correct signation;
E) compilation fails compareTo()methed from the comparator interface has
not been implemented
请问答案是多少?
public class Car implements Comparator{
public int wheels = 0;public Car(){};
public Car(int wheels){
this.wheels = wheels;
}
public int compare (Object o1,Object o2){
Car c1 = (Car)o1;
Car c2 = (Car)o2;
return new Integer(c1.wheels).compareTo(new Integer(c2.wheels));}
public String toString(){ return new Integer(wheels).toString();
}
public static void main(String[] args){
Car c1 = new Car(1);
Car c2 = new Car(2);
Car c3 = new Car(3);
TreeSet list = new TreeSet(new Car());
list.add(c3);
list.add(c1);
list.add(c2);
Iterator it = list.iterator();
while (it.hasNext())
System.out.println(it.next()+"");
}
}
A) compilation succeds compare()throws classCastException;
B) compilation succeds.output is 0 1 2 3;C) compilation succeds.output is 1 2 3;D) compilation fails compare() methed does not have the correct signation;
E) compilation fails compareTo()methed from the comparator interface has
not been implemented
请问答案是多少?
解决方案 »
- [关于乱码] windows下项目 在linux系统下运行
- Ext+json 获取后台的json数据 显示到grid中?(急!!求助)
- web service 的客户端的问题
- 如何固定若干PC, 除固定的PC 外,不能 Login, 提高安全性.
- Resin中怎样发布Web Service问题
- 我的struts token是不是用错了,大家帮忙啊
- 高手进~~关于servlet容器 优化的问题
- 超链接如何加密?各位学长请指教
- 如何把xml文件转换成chm文件,大家给点意见?
- 关于CMP实体Bean的EJB问题
- 面试题,这样也能执行吗?
- struts能不能用open session in view
1, 12
2, -3.0
3,main不是static吧,执行肯定有异常
4,class Myamath{
public void amath(){
test(int i)
}
public test extends amath{
test1(int i){
//这里应插入什么代码?
}
代码写的错了吧, 如果我按照我的推断你想要的答案是test1(int i)?这个是构造函数啊,如果是的话,选super()吧
5,C
2、-3
3、main函数错误
4、1
四. class Myamath{
public void amath(){
test(int i)
}
public test extends Myamath{
test1(int i){
//这里应插入什么代码?
}
}
1. super();
2. this();
3. this(99);
4. super(99);
那位可有类似的这样的例子?
public static void main(String args){
System.out.println("test is number!")
}
} 请问答案是多少?
请问答案是多少?