Abstract Classes and Methods in Object Oriented Programming

Embed Size (px)

Citation preview

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    1/13

    Abstract Classes and Methods in Object Oriented Programming

    By Dharani Prasanna, IBM India

    Abstract Class: Classes which contain one or more abstract methods or abstract properties, suchmethods or properties do not provide implementation. These abstract methods or properties areimplemented 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 inderived 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.

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    2/13

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

    Then click on save button

    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

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    3/13

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

    Go to Menu path, then Goto -> Method definition

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    4/13

    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.

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    5/13

    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

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    6/13

    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

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    7/13

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

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

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    8/13

    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

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    9/13

    Write the code In between Method and End Method

    Method AREA....

    Endmethod

    Write the below code

    method AREA

    * Local Data DeclarationsDATA: lv_count TYPE i,

    lv_res TYPE i.

    * initialize Count value to '1'

    lv_count = '1'.

    DO 10 TIMES.IF lv_count

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    10/13

    Then save and activate the class and method.

    Finally execute the class (F8)

    It goes to below screen

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    11/13

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

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    12/13

    The out will be displayed like below.

  • 7/31/2019 Abstract Classes and Methods in Object Oriented Programming

    13/13