Professional Documents
Culture Documents
Sub Classes Superclass LCL - AIRPLANE
Sub Classes Superclass LCL - AIRPLANE
Sub Classes Superclass LCL - AIRPLANE
***INCLUDE ZBC404_HF_LCL_AIRPLANE . ****************************************** * Definition part ****************************************** CLASS lcl_airplane DEFINITION. *-----------------------------* Public section *-----------------------------PUBLIC SECTION. TYPES: t_name(25) TYPE c. METHODS: constructor IMPORTING im_name TYPE t_name im_planetype TYPE saplane-planetype, display_attributes. * Static methods CLASS-METHODS: display_n_o_airplanes. *-----------------------------* Protected section *-----------------------------PROTECTED SECTION. * Private attributes DATA: name(25) TYPE c, planetype TYPE saplane-planetype. * Private static attribute CLASS-DATA n_o_airplanes TYPE i. ENDCLASS.
****************************************** * Implementation part ****************************************** CLASS lcl_airplane IMPLEMENTATION. METHOD constructor. name = im_name. planetype = im_planetype. * Counts number of instances n_o_airplanes = n_o_airplanes + 1. ENDMETHOD. METHOD display_attributes. WRITE:/ 'Name:', name, 'Planetype:', planetype. ENDMETHOD. METHOD display_n_o_airplanes. WRITE: / 'No. planes:', n_o_airplanes. ENDMETHOD. ENDCLASS.
PRIVATE SECTION. DATA: n_o_seats TYPE sflight-seatsmax. ENDCLASS. CLASS lcl_passenger_airplane IMPLEMENTATION. METHOD constructor. * The constructor method of the superclass MUST be called withing the * construtor CALL METHOD super->constructor EXPORTING im_name n_o_seats = im_n_o_seats. ENDMETHOD. * The redefined display_attributes method METHOD display_attributes. CALL METHOD super->display_attributes. WRITE: / 'No. seats:', n_o_seats. ENDMETHOD. ENDCLASS. = im_name im_planetype = im_planetype.
DATA:cargomax TYPE scplane-cargomax. ENDCLASS. CLASS lcl_cargo_plane IMPLEMENTATION. METHOD constructor. * The constructor method of the superclass MUST be called withing the * constructor CALL METHOD super->constructor EXPORTING im_name cargomax = im_cargomax. ENDMETHOD. METHOD display_attributes. * The redefined display_attributes method CALL METHOD super->display_attributes. WRITE: / 'Cargo max:', cargomax. ENDMETHOD. ENDCLASS. = im_name im_planetype = im_planetype.
CALL METHOD lcl_airplane=>display_n_o_airplanes. * Create objects CREATE OBJECT o_passenger_airplane EXPORTING im_name = 'LH505' im_planetype = 'Boing 747' im_n_o_seats = 350. CREATE OBJECT o_cargo_plane EXPORTING im_name = 'AR13' im_planetype = 'DC 3' im_cargomax = 35. * Display attributes CALL METHOD o_passenger_airplane->display_attributes. CALL METHOD o_cargo_plane->display_attributes. * Call static method display_n_o_airplanes * Note: The syntax for calling a superclass method, differs from the syntax when calling a * subclass method. * When calling a superclass => must be used instead of -> CALL METHOD lcl_airplane=>display_n_o_airplanes.
OUTPUT Result: No. planes: 0 Name: LH505 Planetype: Boing 747 No. seats: 350 Name: AR13 Planetype: DC 3 Cargo max: 35,0000 No. planes: 2