注:number初始值5 通过METOD:increment 三次循环后,输出为8
REPORT ZZ_DEMO_OF_CLASS.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
DATA count TYPE i.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD.
METHOD increment.
ADD 1 TO count.
ENDMETHOD.
METHOD get.
get_value = count.
ENDMETHOD.
ENDCLASS.
DATA number TYPE i VALUE 5.
DATA cnt TYPE REF TO counter.
START-OF-SELECTION.
CREATE OBJECT cnt.
CALL METHOD cnt->set EXPORTING set_value = number.
DO 3 TIMES.
CALL METHOD cnt->increment.
ENDDO.
CALL METHOD cnt->get IMPORTING get_value = number.
WRITE number.
阅读(803) | 评论(0) | 转发(0) |