Quiz 7

Friday

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

  1. In an inheritance relationship, what is the general class?

    1. subclass
    2. superclass
    3. slave class
    4. child class
  2. What keyword refers to an object’s superclass?

    1. super
    2. base
    3. this
    4. extends
  3. Which superclass members cannot be accessed by its subclasses?

    1. public
    2. protected
    3. private
    4. All of the above can be accessed by the subclasses.
  4. Is the following statement correct, and why?

    A method in a subclass that has the same method signature as a method in the superclass is an example of method overloading.

    Answer: False, this is an example of method overriding.

  5. Find and correct the error in the following program.

    class Vehicle {
      public double price;

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

    class Car extends Vehicle {

      public Car(double price) {
        super.price = price;
      }
    }

    Correction:

    class Vehicle {
      public double price;

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

    class Car extends Vehicle {

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

    Or:

    class Vehicle {
      public double price;

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

    class Car extends Vehicle {

      public Car(double price) {
        super.price = price;
      }
    }

Student Performance and Statistics

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

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

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

Q1 1.0 / 1 Q2 0.6 / 1 Q3 0.4 / 1 Q4 0.5 / 1 Q5 0.3 / 1