ABAP Keyword Documentation → ABAP - Reference → Declarative statemnts → Classes and Interfaces → CLASS → CLASS - DEFINITION
PROTECTED SECTION
Other versions: 7.31 | 7.40 | 7.54
Syntax
PROTECTED SECTION.
Effect
You can only use this statement in the declaration part of a class. It defines the protected
visibility section of the class class
.
All components of the class declared in the area behind the statement PROTECTED SECTION
can be addressed directly only in the subclasses of the class and in the class itself (plus its
friends), if allowed by the
package concept. Protected methods in subclasses can be redefined.
Notes
- The class is the smallest encapsulation unit in ABAP Objects. This is the reason why a method cannot only use the protected components of the own class but also all instances of the same class.
- In subclasses, it is not possible to access the protected components of the superclasses using reference variables of the type of the superclass, because otherwise an attribute of an object of the dynamic type of the superclass or another subclass could be changed. In the last case, a warning is produced by the extended syntax check.
- A subclass cannot access the protected components of a subclass of a different branch of the inheritance hierarchy even though they are inherited from a shared superclass.
-
The declaration of attributes in the protected section does not prevent methods in subclasses or in the class itself from passing
references to these attributes in the form of
reference variables or
field symbols, so that the attributes become visible and modifiable outside the protected section.
Example
See Visibility Sections.