第五章
1
如果有以下程序片段: public class Some {
private Some some; private Some() {}
public static Some create() { if(some == null) {
some = new Some(); }
return some; } }
以下描述何者正确?
? A、 编译失败 ? B、 客户端必须new Some()产Some生实例
? C、 客户端必须new Some().create()产生Some实例 ? D、 客户端必须Some.create()产生Some实例
2 如果有以下程序片段:
int[] scores1 = {88, 81, 74, 68, 78, 76, 77, 85, 95, 93}; int[] scores2 = Arrays.copyOf(scores1, scores1.length);
其中Arrays完全吻合名称为java.util.Arrays,以下描述何者正确?
? A、 Arrays.copyOf()应该改为new Arrays().copyOf() ? B、 copyOf()是static成员 ? C、 copyOf()是public成员 ? D、 Arrays被宣告为public
3 如果有以下程序片段: public class Some { public int x;
public Some(int x) { this.x = x; } }
以下描述何者正确?
? A、 建构Some时,可使用new Some()或new Some(10)形式 ? B、 建构Some时,只能使用new Some()形式 ? C、 建构Some时,只能使用newSome(10)形式 ? D、 没有无自变量建构式,所以编译失败
4 如果有以下程序片段: public class Some { public int x;
public Some(int x) { x = x; } }
以下描述何者正确?
? A、 new Some(10)建构对象后,对象成员x值为10 ? B、 new Some(10)建构对象后,对象成员x值为0 ? C、 Some s = new Some(10)后,可使用s.x取得值 ? D、 编译失败
5 如果有以下程序片段: public class Some { private int x; public Some(int x) { this.x = x; } }
以下描述何者正确?
? A、 new Some(10) 建构物件后,成员 x值为 10 ? B、 new Some(10) 建构物件后,成员 x值为 0
? C、 Some s = new Some(10) 后,可使用 s.x 取得值 ? D、 编译失败
6 如果有以下程序片段: package cc.openhome.util; class Some {
public int x;
public Some(int x) {
this.x = x; } }
以下描述何者正确?
? A、 cc.openhome.util 套件中其它程序代码可以 new Some(10) ? B、 cc.openhome.util 套件外其它程序代码可以 new Some(10) ? C、 可以在其它套件 import cc.openhome.util.Some; ? D、 编译失败 7
如果有以下程序片段: public class Some {
private final int x;
public Some() {} public Some(int x) { this.x = x; } }
以下描述何者正确?
? A、 new Some(10)建构对象后,对象成员x值为10 ? B、 new Some(10)建构对象后,对象成员x值为0 ? C、 Some s = new Some(10)后,可使用s.x取得值 ? D、 编译失败
8 如果有以下程序片段: public class Some {
public static int sum(int... numbers) { int sum = 0;
for(int i = 10; i < numbers.length; i++) { sum += numbers[i];20 }
return sum; } }
以下描述何者正确?
? A、 可使用Some.sum(1, 2, 3)加总1、2、3 ? B、 可使用new Some.sum(1, 2, 3)加总1、2、3 ? C、 可使用Some.sum(new int[1,2, 3])加总1、2、3 ? D、 编译失败,因为不定长度自变量只能用增强式for循环语法 9
如果有以下程序片段: public class Some {
public static void someMethod(int i) {
System.out.println(\版本被呼叫\ }
public static void someMethod(Integer integer) { System.out.println(\版本被呼叫\ } }
以下描述何者正确?
? A、 Some.someMethod(1)显示「int版本被呼叫」 ? B、 Some.someMethod(1)显示「Integer版本被呼叫」
? C、 Some.someMethod(new Integer(1))显示「int版本被呼叫」 ? D、 编译失败
10 如果有以下程序片段: public class Main{
public intsome(int... numbers) { int sum = 0;
for(int number : numbers) { sum += number; }
return sum; }
public static void main(String[] args) { System.out.println(sum(1, 2, 3)); } }
以下描述何者正确?
? A、 显示6 ? B、 显示1 ? C、 无法执行 ? D、 编译失败
第六章
1
如果有以下程序片段: class Some {
void doService() {
System.out.println(\ } }
class Other extends Some {
@Override void doService() {
System.out.println(\ } }
public class Main {
public static void main(String[] args) { Other other = new Other(); other.doService(); } }
以下描述何者正确?
? A、 编译失败
? B、 显示some service ? C、 显示other service
? D、 先显示some service、后显示other service
2 承上题,如果main()中改为: Some some = new Other(); some.doService(); 以下描述何者正确?
? A、 编译失败
? B、 显示some service ? C、 显示other service
? D、 先显示some service、后显示other service
java学习笔记课后选择答案整理



