Using Inheritance


Here we take an earlier program where two classes, Company and Employee have some common behavior; they are both named. The goal of this Magercise is to create a new common superclass that avoids duplication of code.

Inheritance is discussed in detail in the course notes.

Work Location

Perform all work for this magercise in VisualAge project MageLang Magercises, package magercises.inheritance.

If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name.

Tasks

Perform the following tasks:

  1. Create a new class, NamedEntity, that incorporates the naming behavior common to the classes Company and Employee. In addition to a constructor, it should have two methods, a public one to get the name, and a protected one to set the name.

  2. Modify the Employee class to use the new superclass.

  3. Modify the Company class to use the new superclass.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.