Monday, March 25, 2013

Final Method cannot be redefined


Final Method cannot be redefined. If we declare a method with FINAL statement then that method cannot be declared with REDEFINITION. In this case syntax error will come at the time of compilation as mentioned below:



Below we have created another version of the program where we have changed the name of the method in the child class. That's mean here the program has two different methods in parent and child class. Being a child/sub class it is inheriting all the data and methods from parent class.



*&---------------------------------------------------------------------*
*& Report  ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zsr_test.

*----------------------------------------------------------------------*
*       CLASS parent DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS parent DEFINITION.
  PUBLIC SECTION.
    DATA v_txt TYPE char50.
    METHODS m_par FINAL.
ENDCLASS.                    "parent DEFINITION

*----------------------------------------------------------------------*
*       CLASS parent IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS parent IMPLEMENTATION.
  METHOD m_par.
    v_txt = 'Final Method in Parent Class'.
    WRITE / v_txt.
  ENDMETHOD.                    "m_par
ENDCLASS.                    "parent IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS child DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS child DEFINITION INHERITING FROM parent.
  PUBLIC SECTION.
    METHODS m_chi FINAL.
ENDCLASS.                    "child DEFINITION

*----------------------------------------------------------------------*
*       CLASS child IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS child IMPLEMENTATION.
  METHOD m_chi.
    CALL METHOD m_par.
    v_txt = 'Final Method in Child Class'.
    WRITE / v_txt.
  ENDMETHOD.                    "m_chi
ENDCLASS.                    "child IMPLEMENTATION

START-OF-SELECTION.
  DATA: obj_chi TYPE REF TO child.
  CREATE OBJECT obj_chi.
  CALL METHOD obj_chi->m_chi.


Below is the Output:


9 comments:

simashree said...

Thank you for such guidance about astrology,Best Blog on Astrology Services in Chennai

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

sanayamohit 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!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

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

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

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

suganya said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

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

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

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

suganya said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

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

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

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

Priya Kannan said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

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

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

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

sameera sam said...


It's so nice article thank you for sharing a valuable content
SAP MDG Online Access

calfre services said...

ood post! Thanks for sharing this Information.The information you Provided is much useful on
sap-hr abap online classes