Quiz 7

Wednesday

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

  1. What keyword in the class header indicates that a class inherits from another class?

    1. derives
    2. specializes
    3. inherits
    4. extends
  2. In a subclass constructor, a call to the superclass constructor ________

    1. may appear but only as the very first statement.
    2. may appear but only as the very last statement.
    3. may not appear.
    4. may appear, and the position does not matter.
  3. Two methods in the same class share the same method name. This ________

    1. is an example of method overloading.
    2. is an example of method overriding.
    3. is an example of method composition.
    4. generates a compiler error.
  4. Which one of the following is the explicit call to the superclass’s default constructor?

    1. default()
    2. class()
    3. super()
    4. base()
  5. Find and correct the error in the following program.

    class Vehicle {
      private double price;

      public Vehicle(final double price) {
        this.price = price;
      }
    }

    class Car extends Vehicle {

      public Car(final double price) {
        super(price);
      }

      public void setPrice(final double price) {
        super.price = price;
      }
    }

    Correction:

    class Vehicle {

      // Change the access specifier to public, protected, or default.
      double price;

      public Vehicle(final double price) {
        this.price = price;
      }
    }

    class Car extends Vehicle {

      public Car(final double price) {
        super(price);
      }

      public void setPrice(final double price) {
        super.price = price;
      }
    }

    Or:

    class Vehicle {
      private double price;

      public Vehicle(final double price) {
        this.price = price;
      }

      public void setPrice(final double price) {
        this.price = price;
      }
    }

    class Car extends Vehicle {

      public Car(final double price) {
        super(price);
      }
    }

Student Performance and Statistics

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

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

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

Q1 0.9 / 1 Q2 0.9 / 1 Q3 0.5 / 1 Q4 0.9 / 1 Q5 0.5 / 1