Starting from:

$30

CPT121-Task 6.1.3 Inheritance and Subclass Basics Solved

1.     In the following pair of classes identify the superclass and subclass: a) Employee / Manager 

b)  Polygon / Triangle 

c)   Vehicle / Car 

d)  GeometricObject / Rectangle 

e)  Integer / Number 

f)   Object/Person 

2.     If class C extends class B and class B extends class A then which of the following statement is true?

a)  an instance of C can use all public methods of classes A, B and C 

b) an instance of A can use all public methods of classes A, B and C

3.     Extend the Account class to create a new subclass called ChequeAccount for modelling a cheque account which incorporates the following functionality:

•        Cheque accounts can use an overdraft facility, so the new class will need instance variables for the overdraft limit and the amount overdrawn.

•       

 
 
 
 
 

 

 

The overdraft should not be used unless the current balance is insufficient to cover a

withdraw.

•        Cheque account holders may be charged for withdrawals or transfers, so the new class will also need a new instance variable for the number of transactions that have been made.

•        A new constructor will be required that accepts the account id, name, initial balance and overdraft limit. This constructor should use the super() facility to initialize the account id, name and balance.

•        This constructor should set the amount overdrawn to 0 and the transaction count to 0.

•        Define another (overloaded) constructor which only accepts the account name, id and balance for the new ChequeAccount (for customers who do not wish to use the overdraft facility yet)

•        This constructor should set the overdraft limit to 0, amount overdrawn to 0 and transaction count to 0

•        Decide whether accessors and/or mutators will be required for the three new instance variables.

4.     Write a program which creates two CAccount objects and trace where the details supplied for each object will be stored upon construction. Describe how the various values supplied when creating the find their way into the corresponding superclass and subclass-level instance variables?

More products