Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  Classes and Interfaces →  ABAP Objects - Overview →  Classes →  Components of Classes →  Constructors of Classes 

Visibility of Instance Constructors

For technical reasons, the the instance constructor of a class is declared in a visibility section and is therefore theoretically visible to the corresponding consumers. However, an instance constructor is only executed when an object of this class is created using CREATE OBJECT. Therefore, the instance constructor is only visible to those consumers of a class that can also create objects of this class.

The additions CREATE PUBLIC|PROTECTED|PRIVATE of the statement CLASS determine whether every consumer, only the heirs, or just the class itself can create objects of the class. This means that these additions define the actual visibility of the instance constructor. Therefore the following applies:

  • The instance constructor of a class defined using CREATE PUBLIC can be called by any consumer.
  • The instance constructor of a class defined using CREATE PROTECTED can only be called by the class itself and its subclasses.
  • The instance constructor of a class defined using CREATE PRIVATE can only be called by the class itself.

This has the following important consequence:

If a class was defined using CREATE PRIVATE, only the class itself can instantiate itself. Subclasses of this class cannot even instantiate themselves, because they would have to call the superclass constructor using CALL super->constructor (also see Inheritance and Instance Creation).

Other versions: 7.31 | 7.40 | 7.54