Exercises
-
Describe, without excessive handwaving, two common uses for interfaces.
-
Given the SupplyDepot, Transport, and CapableOfBeingRefuelled classes/interfaces described earlier in this chapter, add a main routine to Airplane. Then add fields, parameters, and code to SupplyDepot and elsewhere so that a CapableOfBeingRefuelled can tell the service routine how much fuel it takes. Make sure that amount of fuel is decremented at the Depot, and incremented in the object that implements CapableOfBeingRefuelled.
-
Look at the Cloneable interface in javadoc. Take any class that you have written and make it cloneable by making it implement the Cloneable interface.
-
Override
Object.clone()
to do a shallow copy for your class, and also keep count ...
Get Just Java™ 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.