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.TeaB.CoffeeC.CoffeeTeaD.Compilationfails.E.Thecoderunswithnooutput.F.Anexceptionisthrownatruntime.

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.


相关考题:

AprogrammerisdevelopingaclassKey,thatwillbeusedasakeyinastandardjava.util.HashMap.WhichtwomethodsshouldbeoverriddentoassurethatKeyworkscorrectlyasakey?() A.publicinthashCode()B.publicvoidhashCode()C.publicintcompareTo(Objecto)D.publicbooleanequals(Objecto)E.publicbooleancompareTo(Keyk)

package test;class Target{public String name=hello;}What can directly access and change the value of the variable name?() A.any classB.only the Target classC.any class in the test packageD.any class that extends Target

现有:classA{publicStringname=a}classBextendsA{publicStringname=b}执行如下代码后的结果是哪项?()Aa=newB();System.out.println(a.name); A.aB.bC.编译失败D.运行时抛出异常

publicclassKey{privatelongid1;privatelong1d2;//classKeymethods}AprogrammerisdevelopingaclassKey,thatwillbeusedasakeyinastandard java.util.HashMap.WhichtwomethodsshouldbeoverriddentoassurethatKeyworkscorrectlyasakey?()A.publicinthashCode()B.publicbooleanequals(Keyk)C.publicintcompareTo(Objecto)D.publicbooleanequals(Objecto)E.publicbooleancompareTo(Keyk)

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*/}

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*/}

Given:AprogrammerisdevelopingaclassKey,thatwillbeusedasakeyinastandardjava.util.HashMap.WhichtwomethodsshouldbeoverriddentoassurethatKeyworkscorrectlyasakey?() A.publicinthashCode()B.publicbooleanequals(Keyk)C.publicintcompareTo(Objecto)D.publicbooleanequals(Objecto)E.publicbooleancompareTo(Keyk)

在JAVA中,LinkedList类和ArrayList类同属于集合框架类,下列( )选项中的方法是LinkedList类有而ArrayList类没有的。A、add(Objecto)B、add(intindex,Objecto)C、remove(Objecto)D、removeLast()

向ArrayList对象里添加一个元素的方法是A.set(Object o)B.add(Object o)C.setObject(Object o)D.addObject(Object o)