Do not award half marks. Do not deduct marks
for trivial syntactic errors. Alternative correct answers should be
given credit, unless otherwise indicated in the marking scheme.
(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 ]
(i)Interface classes.[1 mark ]
(ii)Variables are implicitly public static final [1mark ]
(iii)Methods are implicitly public abstract [1mark ]
(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 ]
(i)A
sample definition of Drink follows:
public class Drink {
public final int volume;
public abstract int QuantityOfFlavouring();
}
And the following marking scheme should be used:
Correctly structuring the class definition;(1 mark)
Declaring the volume member as final (1 mark)
Declaring the QuantityOfFlavouring method as abstract (1 mark)
[3 marks ]
(ii)A sample definition of Tea follows:
public class Tea extends Drink {
public final int QuantityOfFlavouring() {
return volume/100;
}
}
And the following marking scheme should be used:
Declaring the class to extend Drink (1 mark)
Declaring QuantityOfFlavouring as public final (1 mark)
Ensuring QuantityOfFlavouring calculates and returns the quantity
of tea
required using the formula volume/100 (1 mark)
[3 marks ]
(iii)A sample definition of Medicine follows:
public interface Medicine {
public abstract String ActiveIngredient();
}
And the following marking scheme should be used:
Declaring the class as an interface (1 mark)
Including the signature (without implementing)of ActiveIngredient
(1 mark)
[2 marks ]
(iv)A sample definition of HerbalTea follows:
public class HerbalTea extends Tea implements Medicine {
String ActiveIngredient() {
MyActiveIngredient= herb;
}
public String MyActiveIngredient;
}
And the following marking scheme should be used:
Declaring the class to extend Tea (1 mark)
And to implement Medicine (1 mark)
Declaring the member MyActiveIngredient (1 mark)
Implementing a method to correctly set this member.(1 mark)
[4 marks ]
|