Visibility Areas in Classes

The declaration part of a class can be divided into three visibility areas.

CLASS class DEFINITION.
PUBLIC SECTION.
...
PROTECTED SECTION
...
PRIVATE SECTION
...
ENDCLASS.

These areas define the visibility of class components from outside the class and thus the interfaces of the class for its users. Each class component must be assigned explicitly to one visibility area.

Public Section

All the components declared in the public section are visible to all users and can be addressed by all methods of the class itself and its subclasses. The public components are the interface between the class and all users.

Protected Section

All the components declared in the protected section can be addressed by methods of the class itself and its subclasses. The protected components are a special interface between the class and its subclasses.

Private Section

All the components declared in the private section can be addressed only by methods of the class itself, not its subclasses. The private components are not an special interface between the class and its users.

Encapsulation

The three visibility areas are the basis of the important object attribute, Encapsulation in ABAP Objects. When you define a class, you should not declare components in the public section unless it is neccessary and you should design these public components with particular care. In global classes, these components can not be changed once they are released.