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

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