CS 300 Quiz 错题整理

已检查成绩页中的 11 个已提交 Canvas 测验、全部 17 次 attempt。共发现 4 个测验有历史扣分,8 条错题记录,涉及 6 道不同题目。部分得分题也计入;同题多次出错分别记录。所有测验最终保留成绩均为满分。

题目与答案保留英文,说明使用中文。正确答案的来源分别标明为「Canvas 明示」「后续满分作答验证」或「根据题目推导」,不把隐藏的答案冒充为官方已显示答案。范围为此成绩页的 Canvas quiz(包括名称未带 Quiz 的测验);不包含 zyBooks、TopHat 或编程提交。

1. 02 Module Quiz — Attempt 1 — Question 3

本次总分 14/15 · 本题 0/1

题目

String[] array1 = new String[] {"A","B","C"};
String[] array2 = new String[array1.length];
for (int i = 0; i < array1.length; i++) {
    array2[i] = array1[i];
}

The variable array2 is a ______ copy of array1.

选项:deep / shallow。

  • 我的答案: shallow
  • 正确答案(本题课程判分口径): deep
  • 答案来源: 官方正确答案隐藏;根据仅有的两个选项及 shallow 被判为 0 分推定。
  • 说明: 这里创建了新的数组,修改数组槽位不会改变另一个数组的槽位。严格按 Java 对象复制术语,代码复制的是 String 引用,未逐个新建 String,因此通常也会称为元素引用的浅拷贝;String 不可变,使这种共享不产生可变内容的联动。复习时应区分本题课程口径与严格术语。

2. 02 Module Quiz — Attempt 2 — Question 10

本次总分 13/15 · 本题 0/2

题目

Which statement best describes the functionality of the method doesItWork()?

public static void doesItWork(int[] incoming) {
    int[] workingCopy = incoming;
    int len = incoming.length;
    int tmp;
    for(int i = 0; i < len / 2; i++) {
        tmp = workingCopy[i];
        workingCopy[i] = workingCopy[len - i - 1];
        workingCopy[len - i - 1] = tmp;
    }
}

选项

  1. The method doesItWork() does nothing because the return type of the method is void.
  2. The method doesItWork() does nothing because all changes are made to the shallow copy workingCopy, which are lost when the method returns.
  3. The method doesItWork() takes an array of ints and reverses its content.
  4. The method doesItWork() does nothing because all changes are made to the deep copy workingCopy, which are lost when the method returns.
  • 我的答案: 选项 4。
  • 正确答案: 选项 3 — The method doesItWork() takes an array of ints and reverses its content.
  • 答案来源: 官方正确答案隐藏;根据代码推导。
  • 说明: workingCopy 与 incoming 指向同一数组,循环原地交换首尾元素,因而会改变原数组。void 不代表不能修改传入对象。

3. String Validation — Attempt 1 — Question 5

本次总分 4/5 · 本题 0/1

题目

If you’re working with Java 6 (not Java 11), which is the BEST way to check if a string has meaningful content?

选项

  1. str != null && !str.isBlank()
  2. str != null && str.length() > 0
  3. str != null && !str.isEmpty()
  4. str != null && !str.trim().isEmpty()
  • 我的答案: str != null && !str.isEmpty()
  • 正确答案: str != null && !str.trim().isEmpty()
  • 答案来源: Canvas 明示「This was the correct answer」。
  • 说明: 只检查 isEmpty() 不能排除仅含空格的字符串;该题要求在 Java 6 中判断有意义的内容。

4. 03 Module Quiz — Attempt 1 — Question 2

本次总分 14/15 · 本题 0/1

题目

Check ALL the instance methods defined in the class Toy defined below.

public class Toy {
    public double getPrice() { ... }
    private String color() { ... }
    public static void putAway() { ... }
    private static String changeCategory(String newCategory) { ... };
}

选项:changeCategory、putAway、color、getPrice。

  • 我的答案: changeCategory、color
  • 正确答案: getPrice、color
  • 答案来源: 官方答案标记隐藏,但的同题选择 getPrice、color,获得 1/1。
  • 说明: 实例方法没有 static;private 或 public 不决定它是否为实例方法。此次错选了 changeCategory,漏选了 getPrice。