Answers to Self-Review Exercises (Sections G.1G.5)

  1. G.1

    1. Inheritance.

    2. public and protected.

    3. is-a or inheritance.

    4. has-a or composition.

    5. hierarchical.

    6. public.

    7. constructor.

    8. super.

  2. G.2

    1. True.

    2. False. A has-a relationship is implemented via composition. An is-a relationship is implemented via inheritance.

    3. False. This is an example of a has-a relationship. Class Car has an is-a relationship with class Vehicle.

    4. False. This is known as overriding, not overloading—an overloaded method has the same name, but a different signature.

Get Android How to Program, 3/e 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.