mengyuxin

Redefinition

Apr 18th, 2021
477
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *&---------------------------------------------------------------------*
  2. *& Report ZMENG_REDEFINE
  3. *&---------------------------------------------------------------------*
  4. *&  sap_abap/sap_abap_inheritance.html
  5. *&---------------------------------------------------------------------*
  6. REPORT zmeng_07_redefinition.
  7.  
  8. CLASS super_class DEFINITION.
  9.   PUBLIC SECTION.
  10.   METHODS: addition1 IMPORTING g_a TYPE i
  11.                                g_b TYPE i
  12.          EXPORTING g_c TYPE i.
  13. ENDCLASS.
  14.  
  15. CLASS super_class IMPLEMENTATION.
  16.   METHOD addition1.
  17.     g_c = g_a + g_b.
  18.   ENDMETHOD.
  19. ENDCLASS.
  20.  
  21. CLASS sub_class DEFINITION INHERITING FROM super_class.
  22.   PUBLIC SECTION.
  23.   "如果重新定义一个方法,则不需要在子类中再次输入其接口,而只需要输入方法的名称。
  24.   METHODS: addition1 REDEFINITION.
  25. ENDCLASS.
  26.  
  27. CLASS sub_class IMPLEMENTATION.
  28.   METHOD addition1.
  29.     g_c = g_a + g_b + 10.
  30.   ENDMETHOD.
  31. ENDCLASS.
  32.  
  33. START-OF-SELECTION.
  34.   PARAMETERS: p_a TYPE i, p_b TYPE i.
  35.  
  36.   DATA: h_addition1 TYPE i.
  37.   DATA: h_sub TYPE i.
  38.  
  39.   DATA: ref1 TYPE REF TO sub_class.
  40.  
  41.   CREATE OBJECT ref1.
  42.  
  43.   CALL METHOD ref1->addition1
  44.     EXPORTING g_a = p_a
  45.               g_b = p_b
  46.     IMPORTING g_c = h_addition1.
  47.  
  48.   WRITE:/ h_addition1.
  49.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×