SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

OO ABAP - Instance Constructors get fired at the time of class instantiation

OO ABAP - Instance Constructors get fired at the time of class instantiation

This simple program will show you that instance constructor methods of a class get triggered when an object is created from the class.

This program contains a class C1 with a constructor method which writes out something to indicate that it is triggered. In the START-OF-SELECTION block, the class C1 is instantiated, which triggers the instance constructor method( as is evident by the output as report).



CLASS c1 DEFINITION.
  PUBLIC SECTION.
    METHODS : constructor .
ENDCLASS.

CLASS c1 IMPLEMENTATION.
  METHOD constructor.
    WRITE:/5 'I am constructor'.
    SKIP 2.
  ENDMETHOD.
ENDCLASS.
*************** main program **************
START-OF-SELECTION.
  DATA: obj1 TYPE REF TO c1.
  CREATE OBJECT: obj1.

Output –>

image

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in