Ansicht
Dokumentation

ABENINHERITANCE_STATICAL - INHERITANCE STATICAL

ABENINHERITANCE_STATICAL - INHERITANCE STATICAL

ABAP Short Reference   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.
SAP E-Book

- Inheritance and Static Components

Static components, like all components, exist only once in each inheritance tree, and can be used as of the declaring class:

  • A subclass can access all non-private static components of its superclasses. The class in which the static component is declared is always addressed.
  • From outside, the class component selector can be used to access all visible static components. Each class can be specified in which the component exists, that is, the declaring class and each subclass. Regardless of the class name used in the class component selector, however, the class in which the component is declared is always addressed.

The class in which the component is declared is always the class addressed, regardless of whether the static component is used internally or externally. This is important in the following cases:

Static constructors are called the first time a class is addressed. If a static component is addressed using the class name of a subclass, but is declared in a superclass, only the static constructor of the superclass is called.
A subclass has access to the content of all non-private static attributes of all superclasses. Conversely, a superclass shares its public and protected static attributes with all subclasses. When inherited, static attributes are therefore not only usable in a single class but can also be used in the subtree of the inheritance tree that consists of all subclasses of the defining class. Changes to the values are visible in all involved classes, regardless of the class used to address an attribute.
If an event handler is declared for a static event of a subclass inherited from a superclass, it can only react to this event if it is raised by a method of the subclass or one of its subclasses. If the event is raised in a static method of a superclass, it is not handled, even if the method is called in a subclass or if the name of the subclass is specified.

Note

A static attribute of a class can be declared as a private attribute to prevent it from being used by all subclasses.

Example

Call of a static method of a superclass using the name of a subclass. Before the method is executed, the static constructor of the superclass is executed, but not the static constructor of the subclass. The method returns the value that is set in the superclass.

Example

This example shows how a subclass is used to change a static attribute of a superclass, and how the change is visible in a subclass of a different path in the inheritance tree.

Events in Inheritance






BAL Application Log Documentation   CPI1466 during Backup  
This documentation is copyright by SAP AG.

Length: 3498 Date: 20240504 Time: 184322     sap01-206 ( 71 ms )