Abstract Class and Abstract Method in ABAP OOPS

Abstract Class and Abstract Method in ABAP OOPS



Abstract Class:

  • It is a class which can’t be instantiated or a class for which objects cannot be created. 
  • The instance can be created only from the subclass which inherits the abstract class.
  • It is not mandatory to have abstract method in abstract class but a class must be defined as Abstract if it contains atleast one abstract method. Otherwise, compilation error will be displayed.


Abstract Method:

  • Abstract method is a method without implementation.
  • A method can be defined as an abstract method only if the class is abstract class.
  • The abstract method can be implemented only in its subclass by redefining the method.
  • An Abstract method cannot be private.
  • A static method or class-method cannot be abstract

If the ABSTRACT keyword is removed in the below class definition then it will throw compilation error that Abstract method can be used only in abstract class

CLASS lcl_parent DEFINITION ABSTRACT.
  PUBLIC SECTION.
    METHODS: meth1 ABSTRACT.
ENDCLASS.

Post a Comment

Previous Post Next Post