Chinaunix首页 | 论坛 | 博客
  • 博客访问: 98500
  • 博文数量: 38
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 460
  • 用 户 组: 普通用户
  • 注册时间: 2014-12-27 21:11
文章分类

全部博文(38)

我的朋友

分类: 信息化

2015-05-16 20:40:58

REPORT  zthomas_oo_casting.
"class definition
*----------------------------------------------------------------------*
*       CLASS lcl_super DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_super DEFINITION .
  PUBLIC SECTION.
    METHODS:add
            IMPORTING f_a TYPE i
                      f_b TYPE i
            EXPORTING f_c TYPE i.
ENDCLASS.                    "lcl_super DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_super IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_super IMPLEMENTATION.
  METHOD add.
    f_c = f_a + f_b.
  ENDMETHOD.                    "add
ENDCLASS.                    "lcl_super IMPLEMENTATION
*----------------------------------------------------------------------*
*       CLASS lcl_sub DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_sub DEFINITION INHERITING FROM lcl_super.
*  PUBLIC SECTION.
*  METHODs add.
ENDCLASS.                    "lcl_sub DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_sub IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_sub IMPLEMENTATION.

ENDCLASS.                    "lcl_sub IMPLEMENTATION

START-OF-SELECTION.
  PARAMETERS:p_a TYPE i,
             p_b TYPE i.
  DATA:gv_add TYPE i,
       ref1 TYPE REF TO lcl_sub,
       ref2 TYPE REF TO lcl_super.
  CREATE OBJECT ref1.
  "narrowing casting up-casting
  ref2 = ref1."此处的=就是narrowing casting的操作符
  CALL METHOD ref2->add
    EXPORTING
      f_a = p_a
      f_b = p_b
    IMPORTING
      f_c = gv_add.
WRITE:gv_add.
阅读(562) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~