Ansicht
Dokumentation

ABAPMETHODS_REDEFINITION - METHODS REDEFINITION

ABAPMETHODS_REDEFINITION - METHODS REDEFINITION

General Material Data   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.
SAP E-Book

METHODS, REDEFINITION

Short Reference



METHODS meth $[FINAL$] REDEFINITION.

Addition:

... FINAL

Effect

This statement is possible only in subclasses and redefines an inherited instance method meth. It has the effect that the method meth must be reimplemented in the implementation part of the subclass. The new implementation in the current class hides 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, the implementation of the direct superclass can be called using super->meth. The redefinition is valid for the subclasses of the redefined class until the method is redefined again.

With the exception of the instance constructor, any non-final instance method declared in the public or protected visibility section of a superclass of the current class can be specified for meth. In particular, meth can be an abstract method of an abstract superclass. The redefinition must take place in the same visibility section as the method declaration. The interface and the category of the method (a general or functional instance method or event handler) are not changed in a redefinition. Private methods in superclasses cannot be redefined.

Notes

  • Every object reference that points to an object of a subclass, independent of its static type, addresses the redefined methods. This applies in particular to the self-reference me->.
  • When an instance constructor of a superclass is executed during the creation of an object, the method implementations of the superclass are always called and not the redefined methods of the subclass. Specifying the self-reference me-> has no effect at this time.
  • In the redefinition of a method of an interface, an alias name of the class defined using ALIASES can be specified for meth.
  • The explicit implementation can be omitted when redefining an optional interface method declared using DEFAULT. Instead, the default behavior defined using DEFAULT applies in calls from the current subclass. However, this is not recommended. The default behavior is often not as expected, particularly if an explicit implementation already exists in a preceding superclass.

Addition

... FINAL

A method can be redefined repeatedly along a path in the inheritance tree until the addition FINAL is used in the redefinition. The method is then final as of the current class and can no longer be redefined in its subclasses.

Example

In this example, the method m1 of superclass c1 is redefined in subclass c2, where the original implementation is called using super->m1. Both methods use the private attribute a1 of the respective class. When called using the reference variable oref, which has the static type c1 and the dynamic type c2, the redefined method is executed.








ROGBILLS - Synchronize billing plans   General Material Data  
This documentation is copyright by SAP AG.

Length: 5125 Date: 20240419 Time: 011838     sap01-206 ( 43 ms )