Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College






Download zip file (Right click)


Inheritance Exercise

This is a simple exercise to help you learn how to use inheritance through practice.

Start by doing the following:

  1. Download from the course webpage (Look up and you should see a "Download zip file" link).
  2. Unzip InheritanceExercise
  3. Open the project in Eclipse
  4. Run it to see what it does
Your job is to extend Drawing example so that it can draw triangles and lines in addition to ovals and rectangles. Proceed as follows:
  1. Draw UML class diagrams that represents a refactored version of InheritanceExercise including variable names and types, and methods including parameters and return types. Also, draw the relationships between the classes. Do this without the additional features (triangle and line) yet. In other words, improve the design so that you are ready to include the new features. See below for the UML diagram of the project as it is now.
  2. If doing this in class, show me your UML diagrams. When I approve, go to the next step.
  3. Make changes to the code and test to make sure it still works.
  4. Now update your UML diagrams to include triangles and lines.
  5. If doing this in class, show me your UML diagrams. When I approve, go to the next step.
  6. Implement triangles and lines and test your code.
  7. Answer the following questions
    1. Did you use inheritance? Where? Why?
    2. Did you utilize method overriding? Explain.
    3. Did you use private or protected methods and/or variables? Where and why?
    4. Is polymorphism important in your implementation? Explain.

Original UML Diagrams