publicclassDrinkimplementsComparable{publicStringname;publicintcompareTo(Objecto){return0;}}and:Drinkone=newDrink();Drinktwo=newDrink();one.name=Coffee”;two.name=Tea”;TreeSetset=newTreeSet();set.add(one);set.add(two);AprogrammeriteratesovertheTreeSetandpr

题目

publicclassDrinkimplementsComparable{publicStringname;publicintcompareTo(Objecto){return0;}}and:Drinkone=newDrink();Drinktwo=newDrink();one.name=Coffee”;two.name=Tea”;TreeSetset=newTreeSet();set.add(one);set.add(two);AprogrammeriteratesovertheTreeSetandprintsthenameofeachDrinkobject.Whatistheresult?()

A.Tea

B.Coffee

C.CoffeeTea

D.Compilationfails.

E.Thecoderunswithnooutput.

F.Anexceptionisthrownatruntime.


相似考题
更多“publicclassDrinkimplementsComparable{publicStringname;publicintcompareTo(Objecto){return0; ”相关问题
  • 第1题:

    publicclassScoreimplementsComparable{privateintwins,losses;publicScore(intw,int1){wins=w;losses=1;}publicintgetWins(){returnwins;}publicintgetLosses(){returnlosses;}publicStringtoString(){return<+wins+,+losses+>”;}//insertcodehere}Whichmethodwillcompletethisclass?()

    A.publicintcompareTo(Objecto){/*modecodehere*/}

    B.publicintcompareTo(Scoreother){/*morecodehere*/}

    C.publicintcompare(Scores1,Scores2){/*morecodehere*/}

    D.publicintcompare(Objecto1,Objecto2){/*morecodehere*/}


    参考答案:B

  • 第2题:

    Given:AprogrammerisdevelopingaclassKey,thatwillbeusedasakeyinastandardjava.util.HashMap.WhichtwomethodsshouldbeoverriddentoassurethatKeyworkscorrectlyasakey?()

    A.publicinthashCode()

    B.publicbooleanequals(Keyk)

    C.publicintcompareTo(Objecto)

    D.publicbooleanequals(Objecto)

    E.publicbooleancompareTo(Keyk)


    参考答案:A, D

  • 第3题:

    向ArrayList对象里添加一个元素的方法是

    A.set(Object o)

    B.add(Object o)

    C.setObject(Object o)

    D.addObject(Object o)


    add(Object o)

  • 第4题:

    Given:Which method will complete this class?()

    A.public int compareTo(Object o){/*more code here*/}

    B.public int compareTo(Score other){/*more code here*/}

    C.public int compare(Score s1,Score s2){/*more code here*/}

    D.public int compare(Object o1,Object o2){/*more code here*/}


    参考答案:B

  • 第5题:

    在JAVA中,LinkedList类和ArrayList类同属于集合框架类,下列( )选项中的方法是LinkedList类有而ArrayList类没有的。

    A、add(Objecto)

    B、add(intindex,Objecto)

    C、remove(Objecto)

    D、removeLast()


    正确答案:D