Java 面向对象程序设计 错题整理 chapter 07

2.

The array size is specified when the array is declared.

判断题 (2 分) 2 分

  1.  A.

    false

  2.  B.

    true

8.

If a key is not in the list, the binarySearch method returns _________.

单选题 (1 分) 1 分

  1.  A.

    insertion point - 1

  2.  B.

    -(insertion point + 1)

  3.  C.

    insertion point

  4.  D.

    -insertion point

9.

Suppose int[] numbers = new int[10], what is numbers[0]?

单选题 (1 分) 1 分

  1.  A.

    10.

  2.  B.

    0

  3.  C.

    null

  4.  D.

    undefined.

14.

Which of the following declarations are correct?

多选题 (2 分) 2 分

  1.  A.

    public static void print(double... numbers)

  2.  B.

    public static double... print(double d1, double d2)

  3.  C.

    public static void print(int n, double... numbers)

  4.  D.

    public static void print(String... strings, double... numbers)

  5.  E.

    public static void print(double... numbers, String name)

15.

Identify the problems in the following code.

public class Test {

  public static void main(String argv[]) {

    System.out.println("argv.length is " + argv.length);

  }

单选题 (1 分) 1 分

  1.  A.

    If you run this program without passing any arguments, the program would display argv.length is 0.

  2.  B.

    The program has a compile error because String args[] is wrong and it should be replaced by String args[].

  3.  C.

    The program has a compile error because String argv[] is wrong and it should be replaced by String[] args.

  4.  D.

    If you run this program without passing any arguments, the program would have a runtime error because argv is null.

18.

How can you initialize an array of two characters to 'a' and 'b'?

多选题 (2 分) 2 分

  1.  A.

    char[] charArray = {'a', 'b'};

  2.  B.

    char[2] charArray = {'a', 'b'};

  3.  C.

    char[] charArray = new char[2]; charArray = {'a', 'b'};

  4.  D.

    char[] charArray = new char[]{'a', 'b'};

19.

Analyze the following code:

public class Test {

  public static void main(String[] args) {

    double[] x = {2.5, 3, 4};

    for (double value: x)

      System.out.print(value + " ");

  }

}

单选题 (1 分) 1 分

  1.  A.

    The program displays 2.5 3.0 4.0

  2.  B.

    The program has a syntax error because value is undefined.

  3.  C.

    The program displays 2.5, 3, 4

  4.  D.

    The program displays 2.5 3 4

  5.  E.

    The program displays 2.5, 3.0 4.0

20.

Which of the following is the correct header of the main method?

多选题 (2 分) 2 分

  1.  A.

    static void main(String[] args)

  2.  B.

    public static void main(String args[])

  3.  C.

    public static void main(String[] args)

  4.  D.

    public static void main(String x[])

  5.  E.

    public static void main(String[] x)

24.

Analyze the following code.

int[] list = new int[5];

list = new int[6];

单选题 (1 分) 1 分

  1.  A.

    The code has compile errors because the variable list cannot be changed once it is assigned.

  2.  B.

    The code has runtime errors because the variable list cannot be changed once it is assigned.

  3.  C.

    The code has compile errors because you cannot assign a different size array to list.

  4.  D.

    The code can compile and run fine. The second line assigns a new array to list.

Analyze the following code:

public class Test { 

  public static void main(String[] args) {

    int[] x = {1, 2, 3, 4};

    int[] y = x;

    x = new int[2];

    for (int i = 0; i < y.length; i++)

      System.out.print(y[i] + " ");

  }

}

单选题 (1 分) 1 分

  1.  A.

    The program displays 0 0 3 4

  2.  B.

    The program displays 0 0

  3.  C.

    The program displays 0 0 0 0

  4.  D.

    The program displays 1 2 3 4

41.

The __________ method copies the sourceArray to the targetArray.

 回答错误

单选题 (1 分) 0 分

  1.  A.

    System.copyArrays(sourceArray, 0, targetArray, 0, sourceArray.length);

  2.  B.

    System.arrayCopy(sourceArray, 0, targetArray, 0, sourceArray.length);

  3.  C.

    System.copyarrays(sourceArray, 0, targetArray, 0, sourceArray.length);

  4.  D.

    System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

不懂为啥子不是驼峰命名

43.

Which of the following is correct?

多选题 (2 分) 2 分

  1.  A.

    String[] list = new String[]{"red", "yellow", "green"};

  2.  B.

    String[] list = {"red", "yellow", "green"};

  3.  C.

    String list = {"red", "yellow", "green"};

  4.  D.

    String list = new String{"red", "yellow", "green"};

  5.  E.

    String[] list = new String{"red", "yellow", "green"};

  1. 46.

    The JVM stores the array in an area of memory, called _______, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order.

     

    单选题 (1 分) 1 分

    1.  A.

      stack

    2.  B.

      memory block

    3.  C.

      dynamic memory

    4.  D.

      heap

    答案解释:

49.

Suppose a method p has the following heading:

public static int[] p()

What return statement may be used in p()?

单选题 (1 分) 1 分

  1.  A.

    return {1, 2, 3};

  2.  B.

    return 1;

  3.  C.

    return int[]{1, 2, 3};

  4.  D.

    return new int[]{1, 2, 3};

51.

The __________ method sorts the array scores of the double[] type.

单选题 (1 分) 1 分

  1.  A.

    Njava.util.Arrays.sortArray(scores)

  2.  B.

    java.util.Arrays(scores)

  3.  C.

    java.util.Arrays.sort(scores)

  4.  D.

    java.util.Arrays.sorts(scores)

53.

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 3) return?

单选题 (1 分) 1 分

  1.  A.

    0

  2.  B.

    1

  3.  C.

    -2

  4.  D.

    2

  5.  E.

    -1

Assume double[] scores = {1, 2, 3, 4, 5}, what value does java.util.Arrays.binarySearch(scores, 3.5) return?

单选题 (1 分) 1 分

  1.  A.

    -3

  2.  B.

    -4

  3.  C.

    3

  4.  D.

    0

  5.  E.

    4

8.

If a key is not in the list, the binarySearch method returns _________.

单选题 (1 分) 1 分

  1.  A.

    insertion point - 1

  2.  B.

    -(insertion point + 1)

  3.  C.

    insertion point

  4.  D.

    -insertion point

58.

What is the correct term for numbers[99]?

单选题 (1 分) 1 分

  1.  A.

    index variable

  2.  B.

    indexed variable

  3.  C.

    index

  4.  D.

    array

  5.  E.

    array variable‘

59.

Which of the following statements is valid?

多选题 (2 分) 2 分

  1.  A.

    double d[] = new double[30];

  2.  B.

    char[] c = new char();

  3.  C.

    int[] i = {3, 4, 3, 2};

  4.  D.

    char[] c = new char[4]{'a', 'b', 'c', 'd'};

  5.  E.

    int i = new int(30);

73.

Analyze the following code:

public class Test1 { 

  public static void main(String[] args) {

    xMethod(new double[]{3, 3});

    xMethod(new double[5]);

    xMethod(new double[3]{1, 2, 3});

  }

  public static void xMethod(double[] a) {

    System.out.println(a.length);

  }

}

单选题 (1 分) 1 分

  1.  A.

    The program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect.

  2.  B.

    The program has a compile error because xMethod(new double[]{3, 3}) is incorrect.

  3.  C.

    The program has a runtime error because a is null.

  4.  D.

    The program has a compile error because xMethod(new double[5]) is incorrect.

Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))?

单选题 (1 分) 1 分

  1.  A.

    {1 20 30 40 50}

  2.  B.

    {1, 20, 30, 40, 50}

  3.  C.

    [1 20 30 40 50]

  4.  D.

    [1, 20, 30, 40, 50]

79.

The arraycopy method does not allocate memory space for the target array. The target array must already be created with memory space allocated.

判断题 (2 分) 2 分

  1.  A.

    true

  2.  B.

    false

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值