Help: Using Inheritance


Help is available for each task, or you can go straight to the solution source code.

Task 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.
NamedEntity will have a private String variable to hold the name. The constructor takes a String argument to set the name initially. The first method, getName, will return the value of the name variable. The second method, setName, will take a String argument and set the name variable to be it.

Task 2

Modify the Employee class to use the new superclass.
The constructor for NamedEntity should be called in Employee's constructor, and all references to Employee's name variable changed to the method getName.

Task 3

Modify the Company class to use the new superclass.
See help for the previous task.

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