SJSU/Udacity CS046

Problem Set 9

  1. Interfaces
  2. Comparable Circle
  3. Cast
  4. Smallest
  5. Inheritance
  6. Manager 1
  7. Manager 2
  8. Geometric Solid
  9. True False Question

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 _________:

  1. overriding
  2. overloading
  3. extending
  4. 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:

  1. Question
  2. Quiz
  3. ChoiceQuestion
  4. 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:

  1. Question
  2. FillInQuestion
  3. ChoiceQuestion
  4. 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?

  1. sandwich = sub;
  2. sub = sandwich;
  3. sub = new Sandwich();
  4. 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?

  1. BankAccount
  2. CheckingAccount
  3. Not enough information to say
  4. The code cannot compile

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =