Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

What is an Abstract Class in SAP ABAP?

An abstract class is a class that cannot be instantiated directly. It serves as a blueprint for other classes. Abstract classes typically include:

  • Abstract methods, which are declared but not implemented.
  • Concrete methods, which can be implemented and inherited.
Feature Description
Not instantiable Cannot use CREATE OBJECT on abstract classes.
Used for inheritance Serve as base classes for child classes.
Can contain abstract methods These must be implemented in subclasses.
Can contain concrete methods These can be used directly by child classes.

 

REPORT zrep_lclclass.

CLASS lcl_animal DEFINITION ABSTRACT.
  PUBLIC SECTION.
    METHODS:
      speak ABSTRACT,
      move.         " This can be implemented if needed
ENDCLASS.

CLASS lcl_animal IMPLEMENTATION.
  METHOD move.
    WRITE'Animal is moving'.
  ENDMETHOD.
ENDCLASS.

" Concrete subclass
CLASS lcl_dog DEFINITION INHERITING FROM lcl_animal.
  PUBLIC SECTION.
    METHODS:
      speak REDEFINITION.
ENDCLASS.

CLASS lcl_dog IMPLEMENTATION.
  METHOD speak.
    WRITE'Woof!'.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  " Parent Class
  DATA(lo_animalNEW lcl_animal).
  lo_animal->speak).
  WRITE'Animal can speak'.
  SKIP.
  " child class
  DATA(lo_dogNEW lcl_dog).
  lo_dog->speak).
  lo_dog->move). 

Output:
Check the Program ( CTRL + F2 ).

if not initated the Parent class then the output will be.

Output:

Related Questions

Leave an answer

Leave an answer