Multiple Inheritance Example
*&---------------------------------------------------------------------*
*& Report YTEST_OOABAP6
*&
*&---------------------------------------------------------------------*
*& By Debesh
*&
*&---------------------------------------------------------------------*
REPORT ytest_ooabap6.
*----------------------------------------------------------------------*
* INTERFACE country
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE country.
METHODS set_country.
DATA : country TYPE char10.
ENDINTERFACE. "country
*----------------------------------------------------------------------*
* INTERFACE state
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE state.
METHODS set_state.
DATA : state TYPE char10.
ENDINTERFACE. "state
*----------------------------------------------------------------------*
* CLASS city_bhubaneswar DEFINITION
*----------------------------------------------------------------------*
CLASS city_bhubaneswar DEFINITION.
PUBLIC SECTION.
INTERFACES: country, state.
ENDCLASS. "city_bhubaneswar DEFINITION
*----------------------------------------------------------------------*
* CLASS city_cuttack DEFINITION
*----------------------------------------------------------------------*
CLASS city_bangalore DEFINITION.
PUBLIC SECTION.
INTERFACES: country , state.
ENDCLASS. "city_cuttack DEFINITION
*----------------------------------------------------------------------*
* CLASS city_bhubaneswar IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS city_bhubaneswar IMPLEMENTATION.
METHOD country~set_country.
country~country = 'INDIA'.
ENDMETHOD. "country~set_country
METHOD state~set_state.
state~state = 'ODISHA'.
ENDMETHOD. "state~set_state
ENDCLASS. "city_bhubaneswar IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS city_cuttack IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS city_bangalore IMPLEMENTATION.
METHOD country~set_country.
country~country = 'INDIA'.
ENDMETHOD. "country~set_country
METHOD state~set_state.
state~state = 'KARNATAKA'.
ENDMETHOD. "state~set_state
ENDCLASS. "city_cuttack IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS smart_city DEFINITION
*----------------------------------------------------------------------*
CLASS smart_city DEFINITION.
PUBLIC SECTION .
METHODS display_smart_city.
ENDCLASS. "smart_city DEFINITION
*----------------------------------------------------------------------*
* CLASS smart_city IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS smart_city IMPLEMENTATION.
METHOD display_smart_city.
DATA : lo_bhubaneswar TYPE REF TO city_bhubaneswar.
DATA : lo_bangalore TYPE REF TO city_bangalore.
CREATE OBJECT: lo_bhubaneswar, lo_bangalore.
lo_bhubaneswar->country~set_country( ).
lo_bhubaneswar->state~set_state( ).
lo_bangalore->country~set_country( ).
lo_bangalore->state~set_state( ).
NEW-LINE.
WRITE : 'Bhubaneswar'.
ULINE.
WRITE : 'Country ->'.
WRITE : lo_bhubaneswar->country~country.
NEW-LINE.
WRITE : 'state ->'.
WRITE : lo_bhubaneswar->state~state.
uline.
NEW-LINE.
WRITE : 'Bangalore'.
ULINE.
WRITE : 'Country ->'.
WRITE : lo_bangalore->country~country.
NEW-LINE.
WRITE : 'state ->'.
WRITE : lo_bangalore->state~state.
ENDMETHOD. "display_smart_city
ENDCLASS. "smart_city IMPLEMENTATION
START-OF-SELECTION.
DATA : lo_smart_city TYPE REF TO smart_city.
CREATE OBJECT lo_smart_city.
lo_smart_city->display_smart_city( ).
OUTPUT
Test Object
Bhubaneswar
Country -> INDIA
state -> ODISHA
Bangalore
Country -> INDIA
state -> KARNATAKA
Thanks a lot
ReplyDelete