13
Abstract Class: Classes which contain one or more abstract methods or abstract properties, such methods or properties do not provide implementation. These abstract methods or properties are implemented in the derived classes (Sub-classes). Abstract classes does not create any instances to that class objects Use of Abstract class : We can define some common functionalities in Abstract class (Super-class) and those can be used in derived classes (Sub classes). Step-by-Step Approach to create Abstract classes and Methods TCode: SE24 Enter the name of class as 'Z_DEMO_ABS_CLASS' and press Create Button A pop-up window is displayed, then select "Class" radio button and Press enter It will go to the next screen.

Abstract Class Oops

Embed Size (px)

DESCRIPTION

Abstract Class Oops

Citation preview

Page 1: Abstract Class Oops

Abstract Class:  Classes which contain one or more abstract methods or abstract properties, such methods or properties do not provide implementation. These abstract methods or properties are implemented in the derived classes (Sub-classes).  

Abstract classes does not create any instances to that class objects  

Use of Abstract class:

We can define some common functionalities in Abstract class (Super-class) and those can be used in derived classes (Sub classes).  

Step-by-Step Approach to create Abstract classes and Methods    

TCode: SE24  

Enter the name of class as 'Z_DEMO_ABS_CLASS' and press Create Button  

  

A pop-up window is displayed, then select "Class" radio button and

Press enter    

  

It will go to the next screen.  

Here you enter the Description of the class and then select "Abstract" from Instantiation Drop down list to define the class an abstract class,

Then click on save   button  

Page 2: Abstract Class Oops

  

Go to the "Attributes" tab,  

Enter the Attribute name, Level, Visibility, Type and Description as shown in the screen shot.

Go to Methods tab,

Enter Method name, Level, Visibility and Description as shown in the below screen shot

Page 3: Abstract Class Oops

Double click on the Method name "AREA"; it goes to method Implementation screen.

Go to Menu path, then Goto -> Method definition

  

Page 4: Abstract Class Oops

Pop-up window is displayed. It gives complete information of the method

To define method "AREA" as an abstract method,  

Go to "Attributes" tab, check the check box "Abstract"  

When you click on the "Abstract" check box, pop-up window is displayed,

then press   button.  

Then press "Change" button.  

Page 5: Abstract Class Oops

 

A successful message is displayed like "Method changed successfully"

  

Creating Sub Class:    

TCode: SE24  

Enter the name of class as 'Z_DEMO_ABS_SUB_CLASS' and press Create Button to create sub class  

Page 6: Abstract Class Oops

  

A pop-up window is displayed, then select "Class" radio button and

Press enter    

  

It goes to next screen, here you enter the Description of the class and then

Select the inheritance button    , to inherit the super class then press     button

Page 7: Abstract Class Oops

     

Enter the Super class name as "Z_DEMO_ABS_CLASS", which is being created earlier and press

 button.  

  

The Attributes and methods defined in the super class will automatically come into the sub class. See the below screen shots.  

Page 8: Abstract Class Oops

 

Go to the Methods tab, select the "AREA" method and click on

"Redefine" button    

If you are not Redefine the method and trying to activate the class, it gives syntax error.

Here you can write the code

Page 9: Abstract Class Oops

     

Write the code In between Method and End Method

Method AREA .... Endmethod

Write the below code  

method AREA

*  Local Data Declarations  DATA: lv_count TYPE i,        lv_res TYPE i.

* initialize Count value to '1'  lv_count = '1'.

  DO 10 TIMES.    IF lv_count <= '10'.      lv_res = v_num * lv_count.*     Displa the multiplication table for a Given Number      WRITE: / v_num,               '*',               lv_count,               '=',               lv_res.*     Increment Count value      lv_count = lv_count + 1.    ELSE.      EXIT.    ENDIF.  ENDDO.* Clear variable  CLEAR: v_num.  

endmethod

Page 10: Abstract Class Oops

Then save and activate the class and method.

Finally execute the class   (F8)  

It goes to below screen

Page 11: Abstract Class Oops

Enter the number under V_NUM as "6" and press execute button  .

Page 12: Abstract Class Oops

  

The out will be displayed like below.

Page 13: Abstract Class Oops