Quiz 5

Wednesday

With a piece of paper, write down your name and answers to the following questions.

  1. What is the value of data[3][4] in the following 2D array?

    int[][] data = new int[6][];
    data[0] = new int[] {1, 2, 3, 4, 5};
    data[1] = new int[] {6, 7, 8};
    data[2] = new int[] {9, 10, 11, 12};
    data[3] = new int[] {13, 14, 15, 16, 17, 18};
    data[4] = new int[] {19, 20, 21, 22};
    data[5] = new int[] {23, 24, 25, 26};

    1. 12
    2. 17
    3. 15
    4. Accessing data[3][4] generates an error.
  2. Which of the following is not true about static members?

    1. It is not necessary for an instance of a class to be created to execute static methods or use static fields
    2. Static members are created by placing the keyword static in the definition.
    3. A static method cannot access instance members of the class using the keyword this
    4. Multiple separated instances of a static field may exist
  3. What attribute does the compareTo method of an enum use to compare two enum constants? E.g.,

    public class Program {
      public static void main(final String[] args) {
        int result = Gender.Female.compareTo(Gender.Male);
        :
      }
    }
    enum Gender {
      Confidential,
      Male,
      Female;
    }

    Answer: Ordinal.

  4. Determine if the following statement is correct and why?

    A problem can be solved recursively if it can be broken down into successive smaller problems that are different from the overall problem.

    Answer: False, the successive smaller problems need to be the same as the overall problem

Student Performance and Statistics

A histogram of student performance on percentage grades for Quiz 5 on Wednesday.

100% 2 90 - 99% 7 80 - 89% 1 70 - 79% 2 60 - 69% 0 50 - 59% 0 40 - 49% 0 30 - 39% 0 20 - 29% 1 10 - 19% 0 0 - 9% 0

A table showing the average performance for each question in Quiz 5 on Wednesday.

Q1 1.0 / 1 Q2 0.9 / 1 Q3 0.6 / 1 Q4 1.6 / 2

Friday

With a piece of paper, write down your name and answers to the following questions.

  1. If personA and personB are objects of the same class, Person, to make personB a copy of personA,

    1. we can assign personB to personA, i.e., personB = personA.
    2. we can use the default constructor to create personB with personA data members.
    3. we can write a copy constructor that accepts a Person object as an argument, and makes a field by field copy.
    4. we can use the copy method provided by the Java framework.
  2. What will be returned from a method if the following is the method definition in a UML diagram.

    + getPerson(name:String) : Person

    1. An object of the class Person.
    2. The address of an object of the class Person.
    3. The value stored in the data members of the Person object.
    4. A String representing the name variable.
  3. What is the output of the following program

    import java.util.ArrayList;

    public final class Program {
      public static void main(final String[] args) {
        int var1 = 10;
        String var2 = "Java";
        modify(var1, var2);
        System.out.println("var1 = " + var1 + ", var2 = " + var2);
      }
      public static void modify(int var1, String var2) {
        var1 = 20;
        var2 = "Python";
      }
    }

    1. var1 = 10, var2 = Java
    2. var1 = 10, var2 = Python
    3. var1 = 20, var2 = Java
    4. var1 = 20, var2 = Python
  4. What is the relationship created by object aggregation?

    1. Is a
    2. Sub-class object
    3. Has a
    4. Inner class

Student Performance and Statistics

A histogram of student performance on percentage grades for Quiz 5 on Friday.

100% 3 90 - 99% 0 80 - 89% 0 70 - 79% 3 60 - 69% 0 50 - 59% 2 40 - 49% 0 30 - 39% 0 20 - 29% 0 10 - 19% 0 0 - 9% 0

A table showing the average performance for each question in Quiz 5 on Friday.

Q1 1.0 / 1 Q2 0.4 / 1 Q3 0.9 / 1 Q4 0.9 / 1