*----------------------------------------------------------------------*
* CLASS sward DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS sward DEFINITION.
PUBLIC SECTION.
CLASS-DATA: para(30) TYPE c VALUE 'Hello World!'. "静态变量
CLASS-METHODS: call_static_class. "静态方法
DATA: count TYPE i. "类中的全局变量
METHODS: showdata. "类中的方法
PRIVATE SECTION.
METHODS: private. "定义类的私有方法,只能在该类内部使用
ENDCLASS. "sward DEFINITION
*----------------------------------------------------------------------*
* CLASS sward IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS sward IMPLEMENTATION.
METHOD call_static_class.
WRITE: para.
ENDMETHOD. "call_static_class
METHOD showdata.
CALL METHOD: private.
ENDMETHOD. "SHOWDATA
METHOD private.
WRITE: 'PRIVATE'.
ENDMETHOD. "private
ENDCLASS. "sward IMPLEMENTATION
START-OF-SELECTION.
DATA: obj TYPE REF TO sward. "引用参照类声明变量
DATA: gv_field TYPE string.
CREATE OBJECT obj. "创建类实例对象
gv_field = 'SHOWDATA'. "变量名一定要大写
CALL METHOD: obj->(gv_field). "用变量调用方法
* CALL METHOD: obj->showdata.
* CALL METHOD: sward=>call_static_class. "可以直接用类名调用静态变量和静态方法
ABAP 小白学ABAP面向对象语法01
最新推荐文章于 2024-07-03 13:17:16 发布