Use of NEW - The Instance Operator
-------------------------------------------------------------------------------------------------------------------------
CLASS demo DEFINITION.
PUBLIC SECTION.
METHODS show.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD show.
WRITE :/ 'Hello Show'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
*NEW Operator- variant 1*
DATA obj TYPE REF TO demo.
obj = NEW #( ).
" Here # points to the class DEMO as a place holder. Value of # is determined from the
"target OBJ which is declared as a reference of the class DEMO
CALL METHOD obj->show.
*NEW Operator- variant 2*
" The NEW operator with the class name creates an instance of the class & assigned to the
" variable OBJ1 which is declared in the same line with DATA(obj1).
DATA(obj1) = NEW demo( ).
obj1->show( ).
*NEW Operator - Varianat 3*
NEW demo( )->show( ).
-------------------------------------------------------------------------------------------------------------------------
OUTPUT:
-------------------------------------------------------------------------------------------------------------------------
CLASS demo DEFINITION.
PUBLIC SECTION.
METHODS show.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD show.
WRITE :/ 'Hello Show'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
*NEW Operator- variant 1*
DATA obj TYPE REF TO demo.
obj = NEW #( ).
" Here # points to the class DEMO as a place holder. Value of # is determined from the
"target OBJ which is declared as a reference of the class DEMO
CALL METHOD obj->show.
*NEW Operator- variant 2*
" The NEW operator with the class name creates an instance of the class & assigned to the
" variable OBJ1 which is declared in the same line with DATA(obj1).
DATA(obj1) = NEW demo( ).
obj1->show( ).
*NEW Operator - Varianat 3*
NEW demo( )->show( ).
-------------------------------------------------------------------------------------------------------------------------
OUTPUT:
No comments:
Post a Comment