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题:
A.addthiscodeafterline11:list=(List
B.changelines12and13to:list.add
C.changethemethodsignatureonline11to:publicvoidaddStrings(List<extendsString>list){
D.changethemethodsignatureonline11to:publicvoidaddStrings(List<superString>list){
E.Nochangesarenecessary.Thismethodcompileswithoutwarnings.
第2题:
现有: 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”?()
第3题:
11. List list = // more code here 12. Collections.sort(list, new MyComparator()); Which code will sort this list in the opposite order of the sort in line 12?()
第4题:
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?()
第5题:
11. public class Test { 12. public void foo() { 13. assert false; 14. assert false; 15. } 16. public void bar(){ 17. while(true){ 18. assert false; 19. } 20. assert false; 21. } 22. } What causes compilation to fail?()
第6题:
11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List
第7题:
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.
第8题:
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
int foo() { /* more code here */ }
void foo() { /* more code here */ }
第9题:
for (Iterator o : list.iterator(); o.hasNext (); )
for (Iterator 0 : list)
for (Object o : list.iterator())
for (Object o : list)
第10题:
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.
第11题:
for(Object o : list)
for(Iterator o : list)
for(Object o : list.iterator())
for(Iterator o : list.iterator(); o.hasNext (); )
第12题:
for(Object o : list)
for(Iterator o : list)
for(Object o : list.iterator())
for(Iterator o : list.iterator(); o.hasNext (); )
第13题:
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.
第14题:
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?()
第15题:
public static void search(List
第16题:
现有: 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?()
第17题:
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?()
第18题:
Given: 10. class One { 11. void foo() { } 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two?()
第19题:
3,2,1,
1,2,3,
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第20题:
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.
第21题:
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; } }
第22题:
Collections.reverseSort(list, new MyComparator());
Collections.sort(list, new MyComparator()); list.reverse();
Collections.sort(list, new InverseComparator( new MyComparator()));
Collections.sort(list, Collections.reverseOrder( new MyComparator()));
第23题:
for(Object o : list)
for(Iterator o : list)
for(Object o : list.iterator())
for(Iterator o : list.iterator(); o.hasNext (); )
第24题:
for(char o: list)
for(Object o: getList())
for(Object o: getList();)
for(Object o: o.getList())