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.
第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*/}
第2题:
A.publicinthashCode()
B.publicbooleanequals(Keyk)
C.publicintcompareTo(Objecto)
D.publicbooleanequals(Objecto)
E.publicbooleancompareTo(Keyk)
第3题:
向ArrayList对象里添加一个元素的方法是
A.set(Object o)
B.add(Object o)
C.setObject(Object o)
D.addObject(Object o)
第4题:
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*/}
第5题:
在JAVA中,LinkedList类和ArrayList类同属于集合框架类,下列( )选项中的方法是LinkedList类有而ArrayList类没有的。
A、add(Objecto)
B、add(intindex,Objecto)
C、remove(Objecto)
D、removeLast()