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 system declares the instance constructor of a class in a visibility area; it is therefore theoretically visible to the appropriate users. However, an instance constructor is only executed during the creation of an object of this class using CREATE OBJECT. Therefore the instance constructor is only visible to those users of a class that can also create objects of this class.

The additions CREATE PUBLIC|PROTECTED|PRIVATE of the statement CLASS determine whether every user, 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 user.
  • 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