Friends & Inheritance example in ABAP Objects

Go down

Friends & Inheritance example in ABAP Objects

Post  Admin on Sun Apr 15, 2012 4:31 pm

*&---------------------------------------------------------------------*
*& Report ZSAMPLE_FRIENDS_INHERITANCE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zsample_friends_inheritance.
CLASS c2 DEFINITION DEFERRED.
*----------------------------------------------------------------------*
* CLASS c1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c1 DEFINITION CREATE PROTECTED FRIENDS c2.
PUBLIC SECTION.
METHODS m3.
PROTECTED SECTION.
METHODS m1.
ENDCLASS. "c1 DEFINITION
*----------------------------------------------------------------------*
* CLASS c12 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c12 DEFINITION CREATE PUBLIC INHERITING FROM c1.
PUBLIC SECTION.
METHODS : m2.
DATA : obj_c2 TYPE REF TO c2.
ENDCLASS. "c12 DEFINITION
*----------------------------------------------------------------------*
* CLASS c2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c2 DEFINITION CREATE PROTECTED FRIENDS c12.
PROTECTED SECTION.
METHODS : m1.
DATA : obj_c1 TYPE REF TO c1.
ENDCLASS. "c2 DEFINITION
*----------------------------------------------------------------------*
* CLASS c21 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c21 DEFINITION CREATE PUBLIC INHERITING FROM c2.
PUBLIC SECTION.
METHODS m2.
DATA : obj_c2 TYPE REF TO c2.
ENDCLASS. "c21 DEFINITION
*----------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c1 IMPLEMENTATION.
METHOD m1.
WRITE : / 'Class c1 method M1'.
ENDMETHOD. "m1
METHOD m3.
WRITE :/ 'Class C1 Method M3'.
ENDMETHOD. "m3
ENDCLASS. "c1 IMPLEMENTATION

*----------------------------------------------------------------------*
* CLASS c12 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c12 IMPLEMENTATION.
METHOD m2.
WRITE : / 'Class C12 Method M2'.
DATA : obj_c1 TYPE REF TO c1.
CREATE OBJECT obj_c1.
CREATE OBJECT obj_c2.
CALL METHOD obj_c1->m1.
CALL METHOD obj_c2->m1.
ENDMETHOD. "m1
ENDCLASS. "c12 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS c2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c2 IMPLEMENTATION.
METHOD m1.
WRITE : / 'Class C2 Method M1'.
CREATE OBJECT obj_c1.
CALL METHOD obj_c1->m1.
CALL METHOD obj_c1->m3.
ENDMETHOD. "m1
ENDCLASS. "c2 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS c21 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c21 IMPLEMENTATION.
METHOD m2.
WRITE : / 'Class c21 Method m2'.
CREATE OBJECT obj_c2.
CALL METHOD obj_c2->m1.
CALL METHOD obj_c2->obj_c1->m1.
CALL METHOD obj_c2->obj_c1->m3.
ENDMETHOD. "m1
ENDCLASS. "c21 IMPLEMENTATION

START-OF-SELECTION.
DATA : obj_c12 TYPE REF TO c12.
DATA : obj_c21 TYPE REF TO c21.
CREATE OBJECT obj_c12.
CREATE OBJECT obj_c21.
CALL METHOD obj_c12->m2.
CALL METHOD obj_c21->m2.

Admin
Admin

Posts : 92
Join date : 2012-01-26

http://mysaplab.forumotions.in

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum