Exercises

  1. Describe, without excessive handwaving, two common uses for interfaces.

  2. 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.

  3. 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.

  4. 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.