niusouti.com

单选题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?()Aadd this code after line 11: list = (List) list;Bchange lines 12 and 13 to: list.add(”foo”); 

题目
单选题
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?()
A

 add this code after line 11: list = (List) list;

B

 change lines 12 and 13 to: list.add(”foo”); list.add(”bar”);

C

 change the method signature on line 11 to: public void addStrings(List< extends String> list) {

D

 change the method signature on line 11 to: public void addStrings(List< super String> list) {

E

 No changes are necessary. This method compiles without warnings.


相似考题
更多“11. public void addStrings(List list) {  12. list.add(”foo”)”相关问题
  • 第1题:

    publicvoidaddStrings(Listlist){12.list.add(”foo”);13.list.add(”bar”);14.}Whatmustyouchangeinthismethodtocompilewithoutwarnings?()

    A.addthiscodeafterline11:list=(List)list;

    B.changelines12and13to:list.add(”foo”);list.add(”bar”);

    C.changethemethodsignatureonline11to:publicvoidaddStrings(List<extendsString>list){

    D.changethemethodsignatureonline11to:publicvoidaddStrings(List<superString>list){

    E.Nochangesarenecessary.Thismethodcompileswithoutwarnings.


    参考答案:D

  • 第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”?() 

    • A、 for(Object o : list)
    • B、 for(Iterator o : list)
    • C、 for(Object o : list.iterator())
    • D、 for(Iterator o : list.iterator(); o.hasNext (); )

    正确答案:A

  • 第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?() 

    • A、 Collections.reverseSort(list, new MyComparator());
    • B、 Collections.sort(list, new MyComparator()); list.reverse();
    • C、 Collections.sort(list, new InverseComparator( new MyComparator()));
    • D、 Collections.sort(list, Collections.reverseOrder( new MyComparator()));

    正确答案:D

  • 第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?() 

    • A、for(char o: list)
    • B、for(Object o: getList())
    • C、for(Object o: getList();)
    • D、for(Object o: o.getList())

    正确答案:B

  • 第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?()  

    • A、 Line 13
    • B、 Line 14
    • C、 Line 18
    • D、 Line 20

    正确答案:D

  • 第6题:

    11. public static void append(List list) { list.add(”0042”); }  12. public static void main(String[] args) {  13. List intList = new ArrayList();  14. append(intList);  15. System.out.println(intList.get(0));  16. }  What is the result?() 

    • A、 42
    • B、 0042
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 13.
    • E、 Compilation fails because of an error in line 14.

    正确答案:B

  • 第7题:

    单选题
    11. public static void append(List list) { list.add(”0042”); }  12. public static void main(String[] args) {  13. List intList = new ArrayList();  14. append(intList);  15. System.out.println(intList.get(0));  16. }  What is the result?()
    A

     42

    B

     0042

    C

     An exception is thrown at runtime.

    D

     Compilation fails because of an error in line 13.

    E

     Compilation fails because of an error in line 14.


    正确答案: B
    解析: 暂无解析

  • 第8题:

    多选题
    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?()
    A

    public void foo() { /* more code here */ }

    B

    private void foo() { /* more code here */ }

    C

    protected void foo() { /* more code here */ }

    D

    int foo() { /* more code here */ }

    E

    void foo() { /* more code here */ }


    正确答案: A,D
    解析: 暂无解析

  • 第9题:

    单选题
    现有:  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"?()
    A

      for (Iterator o  :  list.iterator();  o.hasNext  ();  )

    B

      for (Iterator 0  :  list)

    C

      for (Object o  :  list.iterator())

    D

      for (Object o  :  list)


    正确答案: A
    解析: 暂无解析

  • 第10题:

    单选题
    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?()
    A

     The code runs with no output.

    B

     An exception is thrown at runtime.

    C

     Compilation fails because of an error in line 20.

    D

     Compilation fails because of an error in line 21.

    E

     Compilation fails because of an error in line 23.

    F

     Compilation fails because of an error in line 25.


    正确答案: D
    解析: 暂无解析

  • 第11题:

    单选题
    现有:   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”?()
    A

     for(Object o : list)

    B

     for(Iterator o : list)

    C

     for(Object o : list.iterator())

    D

     for(Iterator o : list.iterator(); o.hasNext (); )


    正确答案: B
    解析: 暂无解析

  • 第12题:

    单选题
    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”?()
    A

     for(Object o : list)

    B

     for(Iterator o : list)

    C

     for(Object o : list.iterator())

    D

     for(Iterator o : list.iterator(); o.hasNext (); )


    正确答案: B
    解析: 暂无解析

  • 第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.


    参考答案:C

  • 第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?() 

    • A、 add this code after line 11: list = (List) list;
    • B、 change lines 12 and 13 to: list.add(”foo”); list.add(”bar”);
    • C、 change the method signature on line 11 to: public void addStrings(List< extends String> list) {
    • D、 change the method signature on line 11 to: public void addStrings(List< super String> list) {
    • E、 No changes are necessary. This method compiles without warnings.

    正确答案:D

  • 第15题:

    public static void search(List list) {  list.clear();  list.add(”b”);  list.add(”a”);  list.add(”c”);  System.out.println(Collections.binarySearch(list, “a”));  }  What is the result of calling search with a valid List implementation?()

    • A、0
    • B、1
    • C、a
    • D、b
    • E、c
    • F、The result is undefined.

    正确答案:F

  • 第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?()     

    • A、 for(char o: list)
    • B、 for (Object o:  o.getList())
    • C、 for(Object o: getList();)
    • D、 for(Object o: getList())
    • E、 for(Object o: o.getList();)

    正确答案:D

  • 第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?() 

    • A、 3,2,1,
    • B、 1,2,3,
    • C、 Compilation fails.
    • D、 The code runs with no output.
    • E、 An exception is thrown at runtime.

    正确答案:C

  • 第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?()

    • A、 public void foo() { /* more code here */ }
    • B、 private void foo() { /* more code here */ }
    • C、 protected void foo() { /* more code here */ }
    • D、 int foo() { /* more code here */ }  
    • E、 void foo() { /* more code here */ }

    正确答案:A,C,E

  • 第19题:

    单选题
    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?()
    A

     3,2,1,

    B

     1,2,3,

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     An exception is thrown at runtime.


    正确答案: B
    解析: 暂无解析

  • 第20题:

    单选题
    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?()
    A

     add this code after line 11: list = (List) list;

    B

     change lines 12 and 13 to: list.add(”foo”); list.add(”bar”);

    C

     change the method signature on line 11 to: public void addStrings(List< extends String> list) {

    D

     change the method signature on line 11 to: public void addStrings(List< super String> list) {

    E

     No changes are necessary. This method compiles without warnings.


    正确答案: B
    解析: 暂无解析

  • 第21题:

    单选题
    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?()
    A

     Foo { public int bar() { return 1; } }

    B

     new Foo { public int bar() { return 1; } }

    C

     newFoo() { public int bar(){return 1; } }

    D

     new class Foo { public int bar() { return 1; } }


    正确答案: A
    解析: 暂无解析

  • 第22题:

    单选题
    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?()
    A

     Collections.reverseSort(list, new MyComparator());

    B

     Collections.sort(list, new MyComparator()); list.reverse();

    C

     Collections.sort(list, new InverseComparator( new MyComparator()));

    D

     Collections.sort(list, Collections.reverseOrder( new MyComparator()));


    正确答案: D
    解析: 暂无解析

  • 第23题:

    单选题
    现有:   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”?()
    A

     for(Object o : list)

    B

     for(Iterator o : list)

    C

     for(Object o : list.iterator())

    D

     for(Iterator o : list.iterator(); o.hasNext (); )


    正确答案: B
    解析: 暂无解析

  • 第24题:

    单选题
    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?()
    A

    for(char o: list)

    B

    for(Object o: getList())

    C

    for(Object o: getList();)

    D

    for(Object o: o.getList())


    正确答案: D
    解析: 暂无解析