Chapter 7: Polymorphism and Inheritance

The exercises here are taken from my forthcoming book The Java Developer's Resource.

Quiz

  1. Why can't a class be declared private?

    If a class were declared private, no one could access it, including the runtime. Therefore the class could never be instantiated.

  2. If you can add methods and fields to a subclass, why can't you remove them?

    If you were to remove methods and fields from a subclass, then the subclass could no longer be used as an instance of its superclass. In fact the subclass might not have any relation at all to the superclass if all the superclass's methods and fields were removed.

  3. What's the difference between an abstract class and an interface?

    An interface can be implemented by a class which is already a subclass of another class. A class which is already a subclass of another class cannot extend an abstract class as well. Furthermore, an abstract class can contain non-abstract methods. An interface cannot.


[ Exercises | Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
Last Modified August 21, 1996