EECS2030 Test 4


Instructions

There is one programming question and three other questions.


Programming question

Implement the CombinationLock class. A skeleton can be found here. The API can be found here. A jar with the Lock class can be found here.


Other questions

Question 1

Are non-static attributes of the super class inherited by the sub class? Select the best answer.
A. Yes.
B. No.
C. Only if they are private.
D. Only if they are public.



Question 2

Another name for the aggregation relation is the     relation



Question 3

Consider the following classes.

public class CreditCard
{
   private double balance;

   /**
    * Pay the given part of the balance of this card.
    * For example, if part is 3, then 1/3 of the balance is paid.
    *
    * @param part 1/part is paid.
    * @pre. part > 0
    */
   public void pay(int part)
   {
      this.balance = this.balance - this.balance / part;
   }
}

public class RewardCard extends CreditCard
{
   private int points;

   /**
    * Pay the given part of the balance of this card.
    * For example, if part is 3, then 1/3 of the balance is paid.
    *
    * @param part 1/part is paid.
    * @pre. part >= 0
    */
   public void pay(int part)
   {
      super.pay(part);
   }
}
Point out what is wrong in the above code. ("Use this.getBalance() instead of this.balance" is not the answer.)