Site hosted by Angelfire.com: Build your free website today!
Inheritance and Interfaces
Presentation by: Sachin Thakkar

I. Inheritance
II. Interfaces













III. Multiple Choice

  1. Which of the following would best serve as the interface to the other items listed?

    a. Washing Machine
    b. Refridgerator
    c. MicrowaveOven
    d. Appliance
    e. Dryer



















  2. Given the following class definition:
    public class Vehicle
    {
           public void drive(double miles)
           {
              ...
           }
    }
    Why won't this subclass compile?
    public class Car extends Vehicle
    {
          private void drive(double miles)
          {
            ...
          }
    }
    A) It will compile.
    B) The drive method of the Car class can not have a different return type.
    C) A method can never be declared private.
    D) Car can not have a method with the same name as one in its superclass.
    E) A method must have a different parameter name.





















  3. Given the following Java code:
  4. <><>
    interface Animal {
      public void speak();
    }

    class Canine implements Animal {
      public void speak() {
        System.out.print("Canine:");
      }
      public static void main(String[] args) {
        Animal a = null;
        Canine c = null;
        // What could go here?
      }
    }
    A) c = a;
    B) a = c;
    C) c= new Canine();
    D) B and C
    E) A and C

















  5. Given that the Employee class extends Person class and this segment of code:
    Employee boss = new Employee();
    Person mom = new Person();
    Object anObject;
    Person tom;
    Which of the following assignments are valid?

    A) boss = mom;
    B) anObject = boss;
    C) mom = boss;
    D) B and C
    E) A, B, and C













  6. Given the following code segments:
    public class Country implements Locatable
    {
        ....
    }
    public class Tester
    {
       ....
       Country norway = new Country();
       statement2
    }
    Which of the following statemens would be valid as statement2?

    A) Locatable where = norway;
    B) Locatable where = new Locatable();
    C) Locatable where = Country();
    D) Locatable where = new York();
    E) Country where = new Locatable();




















Free Response Question

An airport needs a program to document the different flights leaving
Given the following class:
     BankAccount
a.) Write a CheckingAccount class that is a subclass of BankAccount that charges transaction fees per transactions, which is entered by the user. You should modify the methods as necessary, add any necessary local variables, and add a deductFees( ) method that deducts the fees for the number of transactions and then resets the transaction count.

b.) Write a SavingsAccount class that is a subclass of BankAccount that earns interest at a fixed rate and has an addInterest( ) method allow the account to earn interest in the account balance. You may use any of the methods added or modified in part A. Assume that the deductFees( ) method works as it should regardless of you answer in part A.


















Answers:
1. D
2. B
3. D
4. D
5. A

FRQ Answers
A.) CheckingAccount
B.) SavingsAccount