Skip to content

Lesson 6 Practice — Employee Hierarchy ​

Create:

text
ZCL_EMPLOYEE_BASE_###
ZCL_SALARIED_EMPLOYEE_###
ZCL_CONTRACTOR_###
ZCL_ABAP_L06_PRACTICE_###

Base Employee owns common:

text
id
name

Subclasses add:

text
SalariedEmployee → annual_salary
Contractor       → hourly_rate

Requirements:

  • use INHERITING FROM;
  • call super->constructor;
  • create a REF TO base variable;
  • assign a SalariedEmployee object to it;
  • call inherited behavior through the base reference;
  • repeat with Contractor.

Questions:

  1. What is the static type of the reference?
  2. What is its dynamic object type after assigning a Contractor?
  3. Why is Contractor an acceptable subtype of Employee in this model?
  4. When would composition be better than inheritance?