August
1999 QUESTION 5 Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
(a) | Explain what is meant by the term single inheritance. | [1] |
Single inheritance is
when a class can extend only one other class.
|
||
(b) | What mechanism does Java provide to allow multiple inheritance. | [1] |
Interfaces
|
||
(c) | Identify: (i) The components of a parent class which are inherited in the sub class. (ii) The components of a parent class which are not inherited in the base class. |
[2] [1] |
(i)
|
||
(ii) The constructor function.
|
||
(d) | (i) Variables can be polymorphic.
Explain what is meant by the term polymorphism. (ii) Explain how polymorphism contrasts to overloading. |
[1] [2] |
(i) A variable can refer to the objects of different forms (types)
|
||
|
||
(e) | (i) Define a class Animal, which has the private attributes
birthday of type Date, and number_legs, of type int. Include in this class a
constructor which takes values that is used to initialize the members. (ii) Derive a subclass of your Animal class, called Dog, which has a public name of type String. Include a constructor, which should have parameters for the members in this class and base class, and initialize the members of this class and those of the base class accordingly. (iii) Consider the following Chihuahua, which is a special type of Dog, but also has characteristics associated with the class Rat: public class Chihuahua extends Dog implements Rat { public Boolean Is_Diseased () { } Give a definition of the interface class Rat, which has the interface function Is_Diseased() and the member diseased, neither of which should be allowed to be overloaded by any class which derives from Rat.
|
[4]
[4]
[4] |
(i) A
sample definition of Animal follows: public class Animal { public
Animal(Date D, int legs) {
|
||
(ii) A sample
definition of dog follows: public
class Dog extends Animal { public
Dog(String N, Date D, int l) {
|
||
(iii) A sample
definition of Rat follows: public
interface Rat {
|