Monday, March 25, 2013

Final Class cannot have Sub Class


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:


2 comments:

Anonymous said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Unknown said...

this site has wonderfull info a bout sap hr abap classes https://www.calfre.com/India/Hyderabad/Ameerpet/SAP-HR-ABAP-Training/listing