The program contains a class C1 with static attribute : NUM . The method : M1 increments the static attribute by 1 and displays the value each time it is called.
In the main START-OF-SELECTION portion, two objects : OBJ1 and OBJ2 are created from class C1.
First, static attribute : NUM is changed and accessed outside the class using the class component selector , ‘=>’.
Then, both objects OBJ1 and OBJ2 are used to call method : M1 which shows the new value of static attribute : NUM .
That the value of the static attribute gets incremented each time when the method M1 of different objects is called shows that this variable is able to retain its value through the entire runtime.
-----------------------------------------------------------------------------------------
Report ysubdel.
CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-DATA: NUM TYPE I.
METHODS: M1.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
Num = num + 1.
write:/5 num.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
c1=>num = 3.
write:/5 c1=>num .
DATA : OREF1 TYPE REF TO C1 ,
OREF2 TYPE REF TO C1 .
CREATE OBJECT : OREF1 ,
OREF2 .
CALL METHOD OREF1->M1 .
CALL METHOD OREF2->M1.
Output 3
4
5
In the main START-OF-SELECTION portion, two objects : OBJ1 and OBJ2 are created from class C1.
First, static attribute : NUM is changed and accessed outside the class using the class component selector , ‘=>’.
Then, both objects OBJ1 and OBJ2 are used to call method : M1 which shows the new value of static attribute : NUM .
That the value of the static attribute gets incremented each time when the method M1 of different objects is called shows that this variable is able to retain its value through the entire runtime.
-----------------------------------------------------------------------------------------
Report ysubdel.
CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-DATA: NUM TYPE I.
METHODS: M1.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
Num = num + 1.
write:/5 num.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
c1=>num = 3.
write:/5 c1=>num .
DATA : OREF1 TYPE REF TO C1 ,
OREF2 TYPE REF TO C1 .
CREATE OBJECT : OREF1 ,
OREF2 .
CALL METHOD OREF1->M1 .
CALL METHOD OREF2->M1.
Output 3
4
5
No comments:
Post a Comment