Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

Method Overriding in SAP ABAP with Example

Method overriding allows a subclass to provide a new implementation of a method that is already defined in the superclass. The method in the subclass must use the REDEFINITION keyword.

When to use it:

  • When a general method in a parent class needs to be customized for specific child behavior.

  • To implement polymorphism (different behavior for the same method call).

CLASS cl_parent DEFINITION.
  PUBLIC SECTION.
    METHODSdisplay.
ENDCLASS.

CLASS cl_parent IMPLEMENTATION.
  METHOD display.
    WRITE'Parent class method'.
  ENDMETHOD.
ENDCLASS.

CLASS cl_child DEFINITION INHERITING FROM cl_parent.
  PUBLIC SECTION.
    METHODSdisplay REDEFINITION.
ENDCLASS.

CLASS cl_child IMPLEMENTATION.
  METHOD display.
    WRITE'Child class method overridden'.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA(lo_objNEW cl_child).
  lo_obj->display). 

OutPut:

Related Questions

Leave an answer

Leave an answer