五.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
请问答案是多少?

解决方案 »

  1.   

    不是高手
    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.   

    1。12
    2、-3
    3、main函数错误
    4、1
      

  3.   

    四是非常明显的代码错误,这个东西根本不可能编译通过的amath 只是一个方法,但 test 居然要去继承这个方法,而不是继承一个类,显然是属于牛头不对马嘴型的错误。就算是继承自 Myamath,这一关过了,下面,test1(int i) 不是构造方法,怎么都不可能执行 super() 方法,super(99) 就更不可能了,因为其父类没有定义带参数的构造方法。而 this, this(99)这两条语句——根本就没有这种写法嘛。真不明白,这种水平的人居然还好意思出题!
      

  4.   

    应是这样写的
    四. 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);
    那位可有类似的这样的例子? 
      

  5.   

    三.class Mytest{
       public static void main(String args){
        System.out.println("test is number!") 
    }
    } 请问答案是多少?
      

  6.   

    System.out.println(010  ¦4)  
         请问答案是多少?