单选题现有:  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.

题目
单选题
现有:  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)


相似考题
更多“单选题现有:  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.”相关问题
  • 第1题:

    现有:  1.  class Propeller2  {  2.   pulolic static void main (String[]args)//add code here?      3.    {  new Propeller2().topGo();  }      4.  5.void topGo()  //add code here?      6.    {   middleGo();  }      7.  8.void middleGo()  //add code here?  9. {   go();  System.out.println ("late middle");  }    void go()  //add code here?      12.    {throw new Exception();  }      13.  }  为使代码通过编译,需要在哪一行加入声明throws Exception?()     

    • A、只在第11行
    • B、在第8行和第11行
    • C、在第5行、第8行和第11行
    • D、在第2行、第5行、第8行和第11行

    正确答案:D

  • 第2题:

    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

  • 第3题:

    现有:  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

  • 第4题:

    1. import java.util.*;  2. public class Example {  3. public static void main(String[] args) {  4. // insert code here  5. set.add(new integer(2));  6. set.add(new integer(l));  7. System.out.println(set);  8. }  9. }  Which code, inserted at line 4, guarantees that this program will output [1,2]? ()

    • A、 Set set = new TreeSet();
    • B、 Set set = new HashSet();
    • C、 Set set = new SortedSet();
    • D、 List set = new SortedList();
    • E、 Set set = new LinkedHashSet();

    正确答案:A

  • 第5题:

    1. import java.util.*;  2. public class Test {  3. public static void main(String[] args) {  4. List strings = new ArrayList();  5. // insert code here  6. }  7. }  Which four, inserted at line 5, will allow compilation to succeed?()

    • A、 String s = strings.get(0);
    • B、 Iterator i1 = strings.iterator();
    • C、 String[] array1 = strings.toArray();
    • D、 Iterator i2 = strings.iterator();
    • E、 String[] array2 = strings.toArray(new String[1]);
    • F、 Iterator i3 = strings.iterator();

    正确答案:A,B,D,E

  • 第6题:

    现有:   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 (); )

    正确答案:A

  • 第7题:

    单选题
    现有:  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
    解析: 暂无解析

  • 第8题:

    单选题
    1. class Pizza {  2. java.util.ArrayList toppings;  3. public final void addTopping(String topping) {  4. toppings.add(topping); 5. }  6. }  7. public class PepperoniPizza extends Pizza {  8. public void addTopping(String topping) {  9. System.out.println(”Cannot add Toppings”);  10. }  11. public static void main(String[] args) {  12. Pizza pizza = new PepperoniPizza();  13. pizza.addTopping(”Mushrooms”);  14. }  15. }  What is the result?()
    A

     Compilation fails.

    B

     Cannot add Toppings

    C

     The code runs with no output.

    D

     A NullPointerException is thrown in Line 4.


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

  • 第9题:

    单选题
    1. import java.util.*;  2. public class Example {  3. public static void main(String[] args) {  4. // insert code here  5. set.add(new integer(2));  6. set.add(new integer(l));  7. System.out.println(set);  8. }  9. }  Which code, inserted at line 4, guarantees that this program will output [1,2]? ()
    A

     Set set = new TreeSet();

    B

     Set set = new HashSet();

    C

     Set set = new SortedSet();

    D

     List set = new SortedList();

    E

     Set set = new LinkedHashSet();


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

  • 第10题:

    单选题
    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
    解析: 暂无解析

  • 第11题:

    单选题
    import java.util.*;  public class LetterASort {  public static void main(String[] args) {  ArrayList strings = new ArrayList();  strings.add(‟aAaA”);  strings.add(”AaA”); strings.add(‟aAa”);  strings.add(”AAaa”);  Collections.sort(strings);  for (String s: strings) { System.out.print(s + “ “); }  }  }  What is the result?()
    A

     Compilation fails.

    B

     aAaA aAa AAaa AaA

    C

     AAaa AaA aAa aAaA

    D

     AaA AAaa aAaA aAa

    E

     aAa AaA aAaA AAaa

    F

     An exception is thrown at runtime.


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

  • 第12题:

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


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

  • 第13题:

    1. class Pizza {  2. java.util.ArrayList toppings;  3. public final void addTopping(String topping) {  4. toppings.add(topping); 5. }  6. }  7. public class PepperoniPizza extends Pizza {  8. public void addTopping(String topping) {  9. System.out.println(”Cannot add Toppings”);  10. }  11. public static void main(String[] args) {  12. Pizza pizza = new PepperoniPizza();  13. pizza.addTopping(”Mushrooms”);  14. }  15. }  What is the result?() 

    • A、 Compilation fails.
    • B、 Cannot add Toppings
    • C、 The code runs with no output.
    • D、 A NullPointerException is thrown in Line 4.

    正确答案:A

  • 第14题:

    现有:  import java.util.*;      class AddStuff2  {  public static void main(String  []  args)  {      TreeSett=new TreeSet();      if (t.add("one"))      if (t.add("two"))     if (t.add ("three"))  add("four");  for (String s  :  t)      System.out.print (s);     }      }      结果为:()     

    • A、 one
    • B、 one three two
    • C、 one two three
    • D、 one two three four
    • E、 four one three two
    • F、编译失败

    正确答案:E

  • 第15题:

    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

  • 第16题:

    现有:  1. import java.util.*;      2.  3. Class FindStuff  {  4.public static void main (String[]args)    {      5,    //insert code here      6.    c.put ("X", 123);      7.    }      8.  } 分别插入到第5行,哪三行允许代码编译?()    

    • A、 Map c= new SortedMap();
    • B、 HashMap c= new HashMap();
    • C、 HashMap c= new Hashtalole();
    • D、 SortedMap c= new TreeMap();
    • E、 ArrayList c= new ArrayList();
    • F、  MaD c = new LinkedHashMap();

    正确答案:B,D,F

  • 第17题:

    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 (); )

    正确答案:A

  • 第18题:

    多选题
    1. import java.util.*;  2. public class Test {  3. public static void main(String[] args) {  4. List strings = new ArrayList();  5. // insert code here  6. }  7. }  Which four, inserted at line 5, will allow compilation to succeed?()
    A

    String s = strings.get(0);

    B

    Iterator i1 = strings.iterator();

    C

    String[] array1 = strings.toArray();

    D

    Iterator i2 = strings.iterator();

    E

    String[] array2 = strings.toArray(new String[1]);

    F

    Iterator i3 = strings.iterator();


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

  • 第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题:

    单选题
    现有:  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
    解析: 暂无解析

  • 第21题:

    单选题
    现有:   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
    解析: 暂无解析

  • 第22题:

    单选题
    1. import java.util.*;  2. class SubGen {  3. public static void main(String [] args) {  4. //insert code here  5. }  6. }  class Alpha { }  class Beta extends Alpha { }  class Gamma extends Beta { }  和四段代码片段:  s1. ArrayList〈? extends Alpha〉 list1 = new ArrayList〈Gamma〉();  s2. ArrayList〈Alpha〉 list2 = new ArrayList〈? extends Alpha〉();  s3. ArrayList〈? extends Alpha〉 list3 = new ArrayList〈? extends Beta〉();  s4. ArrayList〈? extends Beta〉 list4 = new ArrayList〈Gamma〉(); ArrayList〈? extends Alpha〉 list5 = list4;  哪些片段分别插入到第4行,可允许代码编译?()
    A

    只有s1

    B

    只有s3

    C

    只有s1和s3

    D

    只有s1和s4


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

  • 第23题:

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


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

  • 第24题:

    单选题
    现有:  import java.util.*;      class AddStuff2  {  public static void main(String  []  args)  {      TreeSett=new TreeSet();      if (t.add("one"))      if (t.add("two"))     if (t.add ("three"))  add("four");  for (String s  :  t)      System.out.print (s);     }      }      结果为:()
    A

     one

    B

     one three two

    C

     one two three

    D

     one two three four

    E

     four one three two

    F

    编译失败


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