Final Class cannot have Subclass.
Final class which is another type of class in OOPs concept cannot have any child or sub classes. If we create any sub class of final class then syntax error will come as follows:
Below is another version of the program where we have defined two Final classes and in the start of selection we are calling the methods declared in final classes.
*&---------------------------------------------------------------------*
*& Report ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsr_test.
*----------------------------------------------------------------------*
* CLASS cls1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 DEFINITION FINAL.
PUBLIC SECTION.
DATA v_txt TYPE char50.
METHODS m_cls1.
ENDCLASS. "cls1 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 DEFINITION FINAL.
PUBLIC SECTION.
METHODS m_cls2.
ENDCLASS. "cls2 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 IMPLEMENTATION.
METHOD m_cls1.
v_txt = 'Final Class One'.
WRITE / v_txt.
ENDMETHOD. "m_cls1
ENDCLASS. "cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS cls2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 IMPLEMENTATION.
METHOD m_cls2.
WRITE / 'Final Class Two'.
ENDMETHOD. "m_cls2
ENDCLASS. "cls2 IMPLEMENTATION
START-OF-SELECTION.
DATA: obj1 TYPE REF TO cls1,
obj2 TYPE REF TO cls2.
CREATE OBJECT: obj1, obj2.
CALL METHOD: obj1->m_cls1,
obj2->m_cls2.
Below is the Output:
Below is another version of the program where we have defined two Final classes and in the start of selection we are calling the methods declared in final classes.
*&---------------------------------------------------------------------*
*& Report ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsr_test.
*----------------------------------------------------------------------*
* CLASS cls1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 DEFINITION FINAL.
PUBLIC SECTION.
DATA v_txt TYPE char50.
METHODS m_cls1.
ENDCLASS. "cls1 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 DEFINITION FINAL.
PUBLIC SECTION.
METHODS m_cls2.
ENDCLASS. "cls2 DEFINITION
*----------------------------------------------------------------------*
* CLASS cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls1 IMPLEMENTATION.
METHOD m_cls1.
v_txt = 'Final Class One'.
WRITE / v_txt.
ENDMETHOD. "m_cls1
ENDCLASS. "cls1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS cls2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls2 IMPLEMENTATION.
METHOD m_cls2.
WRITE / 'Final Class Two'.
ENDMETHOD. "m_cls2
ENDCLASS. "cls2 IMPLEMENTATION
START-OF-SELECTION.
DATA: obj1 TYPE REF TO cls1,
obj2 TYPE REF TO cls2.
CREATE OBJECT: obj1, obj2.
CALL METHOD: obj1->m_cls1,
obj2->m_cls2.
Below is the Output:
Post a Comment