Quiz 7
Wednesday
With a piece of paper, write down your name and answers to the following questions.
What keyword in the class header indicates that a class inherits from another class?
derivesspecializesinheritsextends
In a subclass constructor, a call to the superclass constructor ________
- may appear but only as the very first statement.
- may appear but only as the very last statement.
- may not appear.
- may appear, and the position does not matter.
Two methods in the same class share the same method name. This ________
- is an example of method overloading.
- is an example of method overriding.
- is an example of method composition.
- generates a compiler error.
Which one of the following is the explicit call to the superclass’s default constructor?
default()class()super()base()
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.
A table showing the average performance for each question in Quiz 7 on Wednesday.
Friday
With a piece of paper, write down your name and answers to the following questions.
In an inheritance relationship, what is the general class?
- subclass
- superclass
- slave class
- child class
What keyword refers to an object’s superclass?
superbasethisextends
Which superclass members cannot be accessed by its subclasses?
publicprotectedprivate- All of the above can be accessed by the subclasses.
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.
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.
A table showing the average performance for each question in Quiz 7 on Friday.