Saturday, 4 March 2017

Abstract class and Abstract Method in ABAP OOPs




REPORT  ZCL_OOPS_TEST.

CLASS zcl_oops_abstract DEFINITION ABSTRACT.

  
PUBLIC SECTION.
  
METHODSdisplay_abstract ABSTRACT.    "" Abstract class can have atleast one abstract method....
  
METHODSdisplay.

ENDCLASS.

CLASS zcl_oops_abstract IMPLEMENTATION.

  
METHOD display"" Normal methods can be implemented here...

    
WRITE:'Super-Class Method' .

    
ENDMETHOD.
""""" Abstract Method can not be implemented here.....

ENDCLASS.




CLASS zcl_oops_sub DEFINITION INHERITING FROM zcl_oops_abstract.

PUBLIC SECTION.

METHODSdisplay_abstract REDEFINITION"" Abstract method can only be implemented afer redefinition by sub-class.

METHODS display_sub.
ENDCLASS.


CLASS zcl_oops_sub IMPLEMENTATION.

METHOD display_abstract"" Abstract method can only be implemented in sub-class of abstract super-class.

WRITE:'Abstract method(Inherited from abstract super class)'.

ENDMETHOD.

METHOD display_sub.

WRITE:'Sub-Class method'.

ENDMETHOD.

ENDCLASS.


START-OF-SELECTION.

DATA l_ref TYPE REF TO zcl_oops_sub.

CREATE OBJECT l_ref.

l_ref
->display( ).
l_ref
->display_abstract( ).
l_ref
->display_sub( ).


Output

No comments:

Post a Comment