1. import java.util.*;  2. class AddStuff {  3. public stati

题目
单选题
1. import java.util.*;  2. class AddStuff {  3. public static void main(String [] args) {  4. TreeSet〈String〉 s = new TreeSet〈String〉();  5. s.add("one");  6. s.add("two");  7. // insert code here  8. for(String s2 : sorted)  9. System.out.print(s2 + " ");  10. }  11. }  和四个代码片段:  s1. SortedSet sorted = s.tailSet(s.first());  s2. SortedSet〈String〉 sorted = s.tailSet(s.first());  s3. SortedSet sorted = (SortedSet)s.tailSet(s.first());  s4. SortedSet sorted = (SortedSet〈String〉)s.tailSet(s.first());  分别插入到第7行,哪项可以编译?()
A

s1

B

s2

C

s2 和 s3

D

s2 和 s4

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列哪个选项的java源文件程序段是不正确的? ( )

A.package testpackage; public class Test{ }

B.import java.io.*; package testpackage; public class Test{ }

C.import java.i.*; class Person{} public class Test{ }

D.import java.io.*; import java.awt.*; public class Test { }


正确答案:B

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

下列Java源程序结构中前三种语句的次序,正确的是

A.import, package, public class

B.import必为首,其他不限

C.public class, import, package

D.package, import, public class


正确答案:D
解析:Java源程序中,首先在程序的最开始用关键字package指明此程序属于哪个包,接着通过import导入外部包中的类或JDK中的类,然后定义类,如public class。

第4题:

Given classes defined in two different files:  1. package util;  2. public class BitUtils {  3. private static void process(byte[] b) { }  4. }  1. package app;  2. public class SomeApp {  3. public static void main(String[] args) {  4. byte[] bytes = new byte[256];  5. // insert code here  6. }  7. }  What is required at line 5 in class SomeApp to use the process method of BitUtils?() 

  • A、 process(bytes);
  • B、 BitUtils.process(bytes);
  • C、 app.BitUtils.process(bytes);
  • D、 util.BitUtils.process(bytes);
  • E、 import util.BitUtils. *; process(bytes);
  • F、 SomeApp cannot use the process method in BitUtils.

正确答案:F

第5题:

1. public class A {  2. void A() {  3. System.out.println(“Class A”);  4. }  5. public static void main(String[] args) {  6. new A();  7. }  8. }  What is the result?()  

  • A、 Class A
  • B、 Compilation fails.
  • C、 An exception is thrown at line 2.
  • D、 An exception is thrown at line 6.
  • E、 The code executes with no output.

正确答案:E

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

1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()

  • A、 Line 33 must be called within a try block.
  • B、 The exception thrown by method1 in class a is not required to be caught.
  • C、 The method declared on line 31 must be declared to throw a RuntimeException.
  • D、 On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.

正确答案:B

第8题:

下列哪个选项的java源文件代码片段是不正确的?

A.package testpackage; public class Test{ }

B.import java. io. *; package testpaekage; public class Test { }

C.import java.io.*; class Person { } public class Test { }

D.import java.io.*; import java. awt.*; public class Test{ }


正确答案:B
解析:Java中的package语句必须是源文件中除去说明以外的第一条语句,导入包语句可以有几个,但是必须位于package语句之后,其他类定义之前,一个源文件中可以有几个类,但最多只能有一个是public的,如果有,则源文件的文件名必须和该类的类名相同。

第9题:

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

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

正确答案:B

更多相关问题