CMS专题

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

题目
单选题
现有:   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
解析: 暂无解析
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

现有包结构:  com |-- x | |-- Alpha.class | | | |-- y | |-- Beta.class | |-- Gamma.class  和类:  //insert code here  import com.*;  import com.x.y.*;  class Test { Alpha a; Beta b; Gamma c; }  哪两行分别插入后可允许代码编译?() 

  • A、package com.;
  • B、import com.x;
  • C、package com.x;
  • D、import com.x.Alpha;

正确答案:C,D

第2题:

1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() 

  • A、 Compilation will succeed for all classes and interfaces.
  • B、 Compilation of class C will fail because of an error in line 2.
  • C、 Compilation of class C will fail because of an error in line 6.
  • D、 Compilation of class AImpl will fail because of an error in line 2.

正确答案:C

第3题:

在jsp页面中导入java.util包,使用下列哪个标记()

A、%@import=”java.util.*”%

B、%@import=”java.util.*”@%

C、%@pageimport=”java.util.*”%

D、%@pagejava=”java.util.*”%


正确答案:D

第4题:

1. public class returnIt (  2. returnType methodA(byte x, double y) (  3. return (short) x/y * 2;  4. )  5. )   What is the valid returnType for methodA in line 2?()  

  • A、 Int
  • B、 Byte
  • C、 Long
  • D、 Short
  • E、 Float
  • F、 Double

正确答案:F

第5题:

与page指令<%@ page import= “java.util.*, java.text.* “ %> 等价的是()。

  • A、<%@ import="“java.util.*" page=""><%@ import="“java.text.*" page=""><%@ import="“java.text.*" page=""><%@ import="“java.util.*" page=""><%@ import="“java.text.*" page=""><%@ import="“java.util.*" page=""><%@ page import= “java.util.* %> <%@ page import= “java.text.* “ %> 
  • B、<%@ page import= “java.util.*”  ,  import= “java.text.* “ %> 
  • C、<%@ page import= “java.util.* “  ;  %> <%@ page import= “java.text.* “  ; %>
  • D、<%@ page import= “java.util.* ; java.text.* “ %>

正确答案:A

第6题:

1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() 

  • A、 Line 4 of class Target can be changed to return i++;
  • B、 Line 2 of class Target can be changed to private int i = 1;
  • C、 Line 3 of class Target can be changed to private int addOne() {
  • D、 Line 2 of class Target can be changed to private Integer i = 0;

正确答案:D

第7题:

Given a file GrizzlyBear.java:  1. package animals.mammals;  2.  3. public class GrizzlyBear extends Bear {  4. void hunt() {  5. Salmon s = findSalmon();  6. s.consume();  7. }  8. }  and another file, Salmon.java:  1. package animals.fish; 2.  3. public class Salmon extends Fish {  4. void consume() { /* do stuff */ }  5. }  Assume both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly?()

  • A、 add public to the start of line 4 in Salmon.java
  • B、 add public to the start of line 4 in GrizzlyBear.java
  • C、 add import animals.mammals.*; at line 2 in Salmon.java
  • D、 add import animals.fish.*; at line 2 in GrizzlyBear.java
  • E、 add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java
  • F、 add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.java

正确答案:A,D

第8题:

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

第9题:

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

第10题:

ClassOne.java: 1. package com.abe.pkg1; 2. public class ClassOne { 3. private char var = ‘a’; 4. char getVar() { return var; } 5. } ClassTest.java: 1. package com.abe.pkg2; 2. import com.abc.pkg1.ClassOne; 3. public class ClassTest extends ClassOne { 4. public static void main(String[] args) { 5. char a = new ClassOne().getVar();6. char b = new ClassTest().getVar(); 7. } 8. } What is the result?()

  • A、 Compilation fails.
  • B、 Compilation succeeds and no exceptions are thrown.
  • C、 An exception is thrown at line 5 in ClassTest.java.
  • D、 An exception is thrown at line 6 in ClassTest.java.

正确答案:A

更多相关问题