Posts

Showing posts with the label Abstract Class

OOPS ABAP: Differences between Abstract class and interfaces

 Abstract classes: In Abstract class have at least one abstract method and others can non-abstract methods. Abstract methods can be public,private or protected. We need to redefine the  abstract method to implement the method in sub class. we can not redefine static methods. Multiple inheritance is not possible. Interfaces: All methods are abstract methods in interfaces. All methods are public. No need to redefine method. we can write the code by clicking on source code button. Multiple inheritance is possible.

OOPS ABAP: Local Abstarct class with example

Local Abstract Class:  They are defined using the keyword ABSTRACT. We can redefine the method using the keyword 'REDEFINITION'. *&---------------------------------------------------------------------* *& Report ZVB_ABSTARCT_CLS *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT  zvb_abstarct_cls . TABLES : vbak , vbap . PARAMETERS :  p_vbeln  TYPE  vbeln_va . DATA : it_vbak  TYPE  ztt_vbak ,   "Table type      is_vbak  TYPE  zst_vbak .  "Global structure *Creating the Abstract class CLASS  abstract_class  DEFINITION  ABSTRACT .    PUBLIC  SECTION .      METHODS  display  ABSTRACT   IMPORTING  pp_vbeln  TYPE  vbeln_va      ...

OOPS ABAP : Abstract Class with Example

Image
Abstract Class: It is a special type of class which has at least one abstract method. Abstract method is that method which has only definition. There will not be any implementation. We can not create object of Abstract class. We can create objects of sub classes of Abstract class. Example: Go to se24 Enter class name and click on create and select 'Abstract' Inst.Generation. Uncheck the Final check box(If it is checked we can not create sub classes) . Press enter.   Enter the method details and click on 'Goto properties' icon .  Check the 'Abstract' check box and clickon 'yes'.   Click on 'change' and activate the class. If we try to write code in 'DISPLAY' method, it throws the message 'Method DISPLAY is abstract.  Using this abstract method in Subclass: Create subclass and it can be final. Goto properties tab,click on superclass button and enter the class name zabstract_cls.    Save and activate. Click on 'redefine' icon.  ...