Inheritance
Consider classes Cat and Mammal. Which is the superclass? |
Mammal |
|
Motorcycle is a subclass of Vehicle. Complete the code in this method header of Motorcycle:
public class Motorcycle ______________________ |
extends Vehicle |
|
| Fill in the blank. Two methods can have the same name but different parameter types. This is called _____________________. | overloading | |
| Fill in the blank. A subclass can provide a different inplementation of a superclass method by providing a method with the same name and parameter types. This is called _____________________. | overriding |
A superclass has a method
public void move()
A subclass provides a method
public void move(int distance)
This is an example of _________:
- overriding
- overloading
- extending
- implementing
Consider the Question hierarchy of this lesson. Assume there is a method
myMethod(Question q). Select all of the following classes whose objects CAN be passed to this method:
-
Question -
Quiz -
ChoiceQuestion -
MultiChoiceQuestion
Consider the Question hierarchy of this lesson. Assume there is a method
myMethod(ChoiceQuestion q). Select all of the following classes whose objects CAN be passed to this method:
Question-
FillInQuestion -
ChoiceQuestion -
MultiChoiceQuestion
Given that Sub is a subclass of Sandwich and the following declarations
Sandwich sandwich = new Sandwich(); Sub sub = new Sub();
Which of the following are legal?
sandwich = sub;-
sub = sandwich; -
sub = new Sandwich(); -
sandwich = new Sub();
The CheckingAccount class extends BankAccount.The BankAccount class has a deposit method and the CheckingAccount class overrides it. Now given this code segment
BankAccount account = new CheckingAccount(); account.deposit(amount);
whose deposit method is called?
BankAccountCheckingAccount- Not enough information to say
- The code cannot compile