Java Reference
In-Depth Information
This class times how long it takes to invoke an empty method bench-
mark, plus the loop overhead. You can now time method invocations by
running the application MethodBenchmark with the number of times to re-
peat the test. The count is taken from the program arguments and de-
coded using the Integer class's parseInt method on the argument string,
as described in " String Conversions " on page 316 .
Any class can override methods from its superclass to declare them ab-
stract , turning a concrete method into an abstract one at that point in
the type tree. This technique is useful, for example, when a class's de-
fault implementation is invalid for a part of the class hierarchy.
You cannot create an object of an abstract class because there would be
no valid implementation for some methods that might well be invoked.
Exercise 3.5 : Write a new extended class that benchmarks something
else, such as how long it takes to run a loop from zero to some passed-
in parameter.
Exercise 3.6 : Change Vehicle so that it has an EnergySource object refer-
ence, which is associated with the Vehicle in its constructor. EnergySource
must be an abstract class, because a GasTank object's measure of fullness
will differ from that of a Battery object. Put an abstractempty method in
EnergySource and implement it in GasTank and Battery classes. Add a start
method to Vehicle that ensures that the energy source isn't empty .
 
Search WWH ::




Custom Search