April 2000
JP219 : JAVA PROGRAMMING

QUESTION 5

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 5

(a)(i)Briefly explain how multiple inheritance is accomplished in Java.[1 mark ]
(ii)State what definitions are implicit about variables in an interface.[1 mark ]
(iii)State what definitions are implicit about methods in a interface.[1 mark ]

(b)(i)The generic type Drink has some specific properties associated with it.In
particular,a Drink has a volume anda QuantityOfFlavouring The
QuantityOfFlavouring is dependent upon which type of drink is under
consideration.Define a class Drink which contains the integer returning
method QuantityOfFlavouring which is to be implemented in all derived
classes,and the integer member volume which is not to be overridden by any
derived classes.[3 marks ]
(ii)A Tea is a particular type ofdrink.To make a perfect cup of tea,1 gramme of
tea is needed per 100 milliliters of water.Using the base class Drink derive a
class Tea which contains an implementation of the derived method
QuantityOfFlavouring such that it will divide the volume by 100,to give the
precise quantity of tea needed for a perfect cup.As this property is consistent
for all teas,this method should not be modifiable for any subsequent derived
classes.[3 marks ]
(iii)Define an interface class,called Medicine which contains a method called
ActiveIngredient which returns a String which will contain the name ofthe
active ingredient in any derived classes.[2 marks ]
(iv)A Herbal Tea is a particular type of tea which also has some medicinal
properties,and therefore is a derivation of both a Tea and a Medicine
Implement a class,called HerbalTea which is a derivation ofthe base class Tea
and the interface Medicine Your class should provide an implementation of
the abstract function ActiveIngredients such that it sets the value of the
private String member MyActiveIngredient to herb [4marks ]