METHODS meth [FINAL] REDEFINITION.
This statement is possible only in subclasses; it redefines an inherited instance method meth. As an effect, the method meth must be re-implemented in the implementation section of the subclass. The new implementation in the current class shadows the implementation of the superclass. The redefined method accesses the private components of the redefined class and not any private components of the same name in the superclass. In the redefined method, you can call the implementation of the direct superclass using the pseudo reference super->meth.
For meth, you can specify any non-final instance method (except the
instance constructor), which is declared in the
public or
protected
visibility section of a superclass of the current class. meth can be an abstract method of an abstract superclass. The
redefinition must happen in the same visibility section as the method declaration. The interface and the method kind
(general or
functional
instance method, event handler) are not changed in a redefinition.
... FINAL
The redefinition is valid for the subclasses of the redefined class until it is again redefined. You
can redefine a method along a path in the inheritance tree until you use the addition
FINAL in theredefinition. Then the method is final staring with the current class and can no longer be redefined in its subclasses.
In this example, the method m1 of superclass c1 is redefined in subclass c2, where the original implementation is called with super->m1. Both methods use the private attribute a1 of the respective class. At the call via the reference variable oref, which has the static type c1 and the dynamic type c2, the redefined method is executed.
CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS m1 IMPORTING p1 TYPE string.
PRIVATE SECTION.
DATA a1 TYPE string VALUE `c1: `.
ENDCLASS.
CLASS c2 DEFINITION INHERITING FROM c1.
PUBLIC SECTION.
METHODS m1 REDEFINITION.
PRIVATE SECTION.
DATA a1 TYPE string VALUE `c2: `.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
CONCATENATE a1 p1 INTO a1.
WRITE / a1.
ENDMETHOD.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m1.
super->m1( p1 ).
CONCATENATE a1 p1 INTO a1.
WRITE / a1.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA oref TYPE REF TO c1.
CREATE OBJECT oref TYPE c2.
oref->m1( `...` ).