add this code after line 11: list = (List
change lines 12 and 13 to: list.add
change the method signature on line 11 to: public void addStrings(List< extends String> list) {
change the method signature on line 11 to: public void addStrings(List< super String> list) {
No changes are necessary. This method compiles without warnings.
第1题:
publicstaticvoidsearch(Listlist){list.clear();list.add(”b”);list.add(”a”);list.add(”c”);System.out.println(Collections.binarySearch(list,a”));}WhatistheresultofcallingsearchwithavalidListimplementation?()
A.0
B.1
C.a
D.b
E.c
F.Theresultisundefined.
第2题:
publicstaticIteratorreverse(Listlist){Collections.reverse(list);returnlist.iterator();}publicstaticvoidmain(String[]args){Listlist=newArrayList();list.add(”1”);list.add(”2”);list.add(”3”);for(Objectobj:reverse(list))System.out.print(obj+,”);}Whatistheresult?()
A.3,2,1,
B.1,2,3,
C.Compilationfails.
D.Thecoderunswithnooutput.
E.Anexceptionisthrownatruntime.
第3题:
11. public void addStrings(List list) { 12. list.add(”foo”); 13. list.add(”bar”); 14. } What must you change in this method to compile without warnings?()
第4题:
public static void search(List
第5题:
1. import java.util.*; 2. class ForInTest { 3. static List list = new ArrayList(); 4. 5. static List getList() { return list; } 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. // insert code here 10. System.out.print(o); 11. } 12. } 第 9 行插入哪一项将输出 abc?()
第6题:
public static Iterator reverse(List list) { Collections.reverse(list); return list.iterator(); } public static void main(String[] args) { List list = new ArrayList(); list.add(” 1”); list.add(”2”); list.add(”3”); for (Object obj: reverse(list)) System.out.print(obj + “,”); } What is the result?()
第7题:
11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List
第8题:
42
0042
An exception is thrown at runtime.
Compilation fails because of an error in line 13.
Compilation fails because of an error in line 14.
第9题:
3,2,1,
1,2,3,
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第10题:
for(char o: list)
for(Object o: getList())
for(Object o: getList();)
for(Object o: o.getList())
第11题:
Foo { public int bar() { return 1; } }
new Foo { public int bar() { return 1; } }
newFoo() { public int bar(){return 1; } }
new class Foo { public int bar() { return 1; } }
第12题:
add this code after line 11: list = (List
change lines 12 and 13 to: list.add
change the method signature on line 11 to: public void addStrings(List< extends String> list) {
change the method signature on line 11 to: public void addStrings(List< super String> list) {
No changes are necessary. This method compiles without warnings.
第13题:
A.addthiscodeafterline11:list=(List
B.changelines12and13to:list.add
C.changethemethodsignatureonline11to:publicvoidaddStrings(List<extendsString>list){
D.changethemethodsignatureonline11to:publicvoidaddStrings(List<superString>list){
E.Nochangesarenecessary.Thismethodcompileswithoutwarnings.
第14题:
现有: 3.import java.util.*; 4.class ForInTest { 5.static List list = new ArrayList(); 6.public static void main (String [] args){ 7. 8.list.add("a"); list.add("b"); list.add("c"); 9.//insert code here 10.System.out.print(o); } } 哪一行插入到第9行将导致输出“abc”?()
第15题:
10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result?()
第16题:
10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. // insert code here 16.); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile?()
第17题:
现有: 1. import java.util.*; 2. class ForInTest { 3.static List list - new ArrayList(): 4. 5.static List getList() { return list; } 6. 7.public static void main (Strincj[] args) { 8.list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print (o); 11. } 12. } 第9行插入哪一项将输出abc?()
第18题:
3. import java.util.*; 4. class ForInTest { 5. static List list = new ArrayList(); 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print(o); 11. } 12. } 哪一行插入到第9行将导致输出“abc”?()
第19题:
0
1
a
b
c
The result is undefined.
第20题:
for(char o: list)
for (Object o: o.getList())
for(Object o: getList();)
for(Object o: getList())
for(Object o: o.getList();)
第21题:
for(Object o : list)
for(Iterator o : list)
for(Object o : list.iterator())
for(Iterator o : list.iterator(); o.hasNext (); )
第22题:
for(Object o : list)
for(Iterator o : list)
for(Object o : list.iterator())
for(Iterator o : list.iterator(); o.hasNext (); )
第23题:
The code runs with no output.
An exception is thrown at runtime.
Compilation fails because of an error in line 20.
Compilation fails because of an error in line 21.
Compilation fails because of an error in line 23.
Compilation fails because of an error in line 25.
第24题:
for(Object o : list)
for(Iterator o : list)
for(Object o : list.iterator())
for(Iterator o : list.iterator(); o.hasNext (); )