单项选择题
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())
点击查看答案&解析
相关考题
-
单项选择题
class Number { public static void main(String [] args) { try { System.out.print(Integer.parseInt("forty ")); } catch (RuntimeException r) { System.out.print("runtime "); } catch (NumberFormatException e) { System.out.print("number "); } } } 结果是什么?()
A.forty
B.number
C.runtime
D.编译失败 -
单项选择题
final class Tree { private static String tree = "tree "; String getTree() { return tree; } } class Elm extends Tree { private static String tree = "elm "; public static void main(String [] args) { new Elm().go(new Tree()); } void go(Tree t) { String s = t.getTree()+Elm.tree+tree+(new Elm().getTree()); System.out.println(s); } } 结果为:()
A.elm elm elm elm
B.tree elm elm elm
C.tree elm tree elm
D.编译失败 -
单项选择题
1. class Animal { Animal getOne() { return new Animal(); } } 2. class Dog extends Animal { 3. // insert code here 4. } 5. 6. class AnimalTest { 7. public static void main(String [] args) { 8. Animal [] animal = { new Animal(), new Dog() } ; 9. for( Animal a : animal) { 10. Animal x = a.getOne(); 11. } 12. } 13. } 和代码: 3a. Dog getOne() { return new Dog(); } 3b. Animal getOne() { return new Dog(); } 第 3 行中插入的哪项将编译且运行无异常?()
A.3a行
B.3b行
C.3a行或3b行
D.既非3a,也非3b
