Constructor gets triggered whenever the object is created but we need to call method to trigger the general method. Here we have a program where we have declared two public methods meth and constructor. Both the method have different operations. When we create the object of the class, the constructor method triggers its operation.
Below is the output:
REPORT zsr_test.
*----------------------------------------------------------------------*
* CLASS cl_construct DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_construct DEFINITION.
PUBLIC SECTION.
METHODS: m_meth, constructor.
ENDCLASS. "cl_construct DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_construct IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_construct IMPLEMENTATION.
METHOD m_meth.
WRITE: / 'General Method'.
ENDMETHOD. "m_meth
METHOD constructor.
WRITE: / 'Constructor gets triggered object is created'.
ENDMETHOD. "constructor
ENDCLASS. "cl_construct IMPLEMENTATION
START-OF-SELECTION. DATA obj TYPE REF TO cl_construct.
CREATE OBJECT obj.
*----------------------------------------------------------------------*
* CLASS cl_construct DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_construct DEFINITION.
PUBLIC SECTION.
METHODS: m_meth, constructor.
ENDCLASS. "cl_construct DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_construct IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_construct IMPLEMENTATION.
METHOD m_meth.
WRITE: / 'General Method'.
ENDMETHOD. "m_meth
METHOD constructor.
WRITE: / 'Constructor gets triggered object is created'.
ENDMETHOD. "constructor
ENDCLASS. "cl_construct IMPLEMENTATION
START-OF-SELECTION. DATA obj TYPE REF TO cl_construct.
CREATE OBJECT obj.
Below is the output:
No comments:
Post a Comment