<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: oops-methodoverriding in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469057#M554859</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;there is no oveloading in abap ooops&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Jul 2007 10:43:42 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-07-03T10:43:42Z</dc:date>
    <item>
      <title>oops-methodoverriding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469055#M554857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there any phenomenon by name method overriding in abap like java.If it was there can any body explain it in detail,or if it was not there ,then is there any other phenomenon which have a similar functionality like method overriding&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2007 08:15:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469055#M554857</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-03T08:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: oops-methodoverriding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469056#M554858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi check this out it may be helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;d) Overloading must have different method signatures whereas overriding must have same signature. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_vehicle DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PUBLIC SECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Signature of method&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;METHODS: set_make&lt;/P&gt;&lt;P&gt;IMPORTING value(im_make) TYPE string " Pass by value&lt;/P&gt;&lt;P&gt;im_model TYPE string," Pass by reference &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS. "zl_lcl_vehicle DEFINITION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_vehicle IMPLEMENTATION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Implementation of method.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;METHOD set_make.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF im_make IS NOT INITIAL&lt;/P&gt;&lt;P&gt;AND im_model IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;gv_make = im_make.&lt;/P&gt;&lt;P&gt;gv_model = im_model.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDMETHOD. "set_make&lt;/P&gt;&lt;P&gt;ENDCLASS. "zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Overloading means changing signature as well as implementation of a method. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Overriding is changing only implementation of method with signature unchanged.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From ABAP perspective, only the CONSTRUCTOR method can be overloaded in a subclass i.e both the signature and implementation can be adapted in subclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other method can't be overloaded. It can only be redefined/overridden i.e implementation changed with signature unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Award points if found useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rajesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2007 09:30:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469056#M554858</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-03T09:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: oops-methodoverriding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469057#M554859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;there is no oveloading in abap ooops&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2007 10:43:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469057#M554859</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-03T10:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: oops-methodoverriding</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469058#M554860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandeep,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Overriding is changing method implementation with signature unchanged.&lt;/P&gt;&lt;P&gt;Overloading is changing signature as well as implementation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ABAP, overlaoding is not possible for methods with one exception. Only the constructor method can be overlaoded in a subclass during inheritance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For all other methods, only overriding is possible. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check out the following programs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;Method overriding&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Definiton)  zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Definition of the Superclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_vehicle DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Visible to all&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    METHODS: set_make      IMPORTING im_make        TYPE string&lt;/P&gt;&lt;P&gt;                                     im_model       TYPE string,&lt;/P&gt;&lt;P&gt;             get_make      EXPORTING ex_make        TYPE string&lt;/P&gt;&lt;P&gt;                                     ex_model       TYPE string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PROTECTED SECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Visible within class and all subclasses&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    DATA gv_n_o_veh TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PRIVATE SECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Only visible within the class&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    DATA: gv_make         TYPE string,   " Vehicle make&lt;/P&gt;&lt;P&gt;          gv_model        TYPE string.   " Type or model&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "zl_lcl_vehicle DEFINITION&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Implementation)  zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Implementation of the Superclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_vehicle IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD set_make.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF im_make  IS NOT INITIAL&lt;/P&gt;&lt;P&gt;       AND im_model IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;      gv_make  = im_make.&lt;/P&gt;&lt;P&gt;      gv_model = im_model.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "set_make&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD get_make.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    ex_make  = gv_make.&lt;/P&gt;&lt;P&gt;    ex_model = gv_model.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "get_make&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.               "zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Definiton)  zl_lcl_car&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Definition of the Subclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_car DEFINITION INHERITING FROM zl_lcl_vehicle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    METHODS: set_vehtype   IMPORTING im_vehtype     TYPE string&lt;/P&gt;&lt;P&gt;                                     im_n_o_veh     TYPE i,&lt;/P&gt;&lt;P&gt;             get_vehtype   EXPORTING ex_vehtype     TYPE string&lt;/P&gt;&lt;P&gt;                                     ex_n_o_veh     TYPE i,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Begin of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;To change the implementation of a superclass instance method in      *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;subclass, without changing the method signature, the method must be  *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;defined in subclass with REDIFINITION addition. There is no need to  *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;define the method parameters and exceptions again.                   *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Redifinition is not possible for private methods.                    *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Redefining methods introduces POLYMORPHISM in classes.               *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;REDEFINITION addition must be used to implement an abstract method   *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;of a superclass in a subclass. However a final method in a           *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;superclass can't be redefined in superclass.                         *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;The constructors of a class are always final and cannot be redefined.*&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;             get_make REDEFINITION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;End of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PRIVATE SECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    DATA gv_vehtype TYPE string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "zl_lcl_car DEFINITION&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Implementation)  zl_lcl_car&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Implementation of the Subclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_car IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD set_vehtype.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF im_vehtype IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;      gv_vehtype  = im_vehtype.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Protected component of superclass can be directly accessed in subclass. *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;The same applies for public components, private compenets of superclass *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;have to be accessed using public or protected methods of superclass.    *&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      gv_n_o_veh  = im_n_o_veh.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "set_vehtype&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD get_vehtype.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    ex_vehtype  = gv_vehtype.&lt;/P&gt;&lt;P&gt;    ex_n_o_veh  = gv_n_o_veh.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "get_vehtype&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Begin of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;When REDIFINITION addition is used with any method in subclass         *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;definition a new implementation part must be specified for the         *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;inherited method.                                                      *&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  METHOD get_make.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;To access the superclass method from the redefined method, use the     *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;pseudo-reference SUPER                                                 *&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    super-&amp;gt;get_make( IMPORTING  ex_make  = ex_make&lt;/P&gt;&lt;P&gt;                                ex_model = ex_model ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "get_make&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;End of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.               "zl_lcl_car&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Declaring a reference variable with reference to the subclass.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;DATA: z_car     TYPE REF TO zl_lcl_car.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: gv_make         TYPE string,&lt;/P&gt;&lt;P&gt;      gv_model        TYPE string,&lt;/P&gt;&lt;P&gt;      gv_vehtype      TYPE string,&lt;/P&gt;&lt;P&gt;      gv_n_o_veh      TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Creating an instance of the subclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  CREATE OBJECT: z_car.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Accessing the public methods of superclass using subclass reference&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  z_car-&amp;gt;set_make( EXPORTING im_make  = 'MARUTI'&lt;/P&gt;&lt;P&gt;                             im_model = '800' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;POLYMORPHISM - There are 2 implementations of the method get_make *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;one in superclass and one in subclass. Since the method is        *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;redefined in subclass, subclass implementation will be executed   *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;if subclass reference is used.                                    *&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  z_car-&amp;gt;get_make( IMPORTING  ex_make  = gv_make&lt;/P&gt;&lt;P&gt;                              ex_model = gv_model ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Accessing the methods of subclass using subclass reference&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  z_car-&amp;gt;set_vehtype( EXPORTING im_vehtype = 'Car'&lt;/P&gt;&lt;P&gt;                                im_n_o_veh = '10' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  z_car-&amp;gt;get_vehtype( IMPORTING ex_vehtype = gv_vehtype&lt;/P&gt;&lt;P&gt;                                ex_n_o_veh = gv_n_o_veh ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  WRITE: / 'Vehicle type :', gv_vehtype,&lt;/P&gt;&lt;P&gt;         / 'Make  :', gv_make,&lt;/P&gt;&lt;P&gt;         / 'Model :', gv_model,&lt;/P&gt;&lt;P&gt;         / 'No of ordered vehicles :', gv_n_o_veh.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;Constructor Overlaoding&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Definiton)  zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Definition of the Superclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_vehicle DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Visible to all&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    METHODS: set_make     IMPORTING im_make        TYPE string&lt;/P&gt;&lt;P&gt;                                    im_model       TYPE string,&lt;/P&gt;&lt;P&gt;             get_make     EXPORTING ex_make        TYPE string&lt;/P&gt;&lt;P&gt;                                    ex_model       TYPE string,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Begin of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Superclass Constructor&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;             constructor  IMPORTING im_n_o_vehicle TYPE  i.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;End of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PROTECTED SECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Visible within class and all subclasses&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    DATA gv_n_o_veh TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PRIVATE SECTION.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Only visible within the class&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    DATA: gv_make         TYPE string,   " Vehicle make&lt;/P&gt;&lt;P&gt;          gv_model        TYPE string.   " Type or model&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "zl_lcl_vehicle DEFINITION&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Definiton)  zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Definition of the Subclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_car DEFINITION INHERITING FROM zl_lcl_vehicle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      METHODS: get_vehtype   EXPORTING ex_vehtype     TYPE string&lt;/P&gt;&lt;P&gt;                                     ex_n_o_veh       TYPE i,&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Begin of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Constructor Overloading. Both the signature and implementation of   *&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;method can be adapted in the subclass.                              *&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;               constructor   IMPORTING ims_n_o_vehicle TYPE i&lt;/P&gt;&lt;P&gt;                                       ims_vehtype     TYPE string.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;End of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PRIVATE SECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    DATA gv_vehtype TYPE string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "zl_lcl_car DEFINITION&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Implementation)  zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Implementation of the Superclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_vehicle IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD set_make.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF im_make  IS NOT INITIAL&lt;/P&gt;&lt;P&gt;       AND im_model IS NOT INITIAL.&lt;/P&gt;&lt;P&gt;      gv_make  = im_make.&lt;/P&gt;&lt;P&gt;      gv_model = im_model.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "set_make&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD get_make.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    ex_make  = gv_make.&lt;/P&gt;&lt;P&gt;    ex_model = gv_model.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "get_make&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Begin of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Superclass constructor implementation&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  METHOD constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    gv_n_o_veh = im_n_o_vehicle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "constructor&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;End of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.               "zl_lcl_vehicle&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;       Class (Implementation)  zl_lcl_car&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       Implementation of the Subclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS zl_lcl_car IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD get_vehtype.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    ex_vehtype  = gv_vehtype.&lt;/P&gt;&lt;P&gt;    ex_n_o_veh  = gv_n_o_veh.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "get_vehtype&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Begin of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Subclass constructor implementation&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  METHOD constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;If subclass constructor is overloaded, it is mandatory to call&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;superclass constructor within subclass constructor, because superclass&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;constructor is meant to be executed when object is created for super&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;or sub class. If subclass constructor is not overloaded, then the&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;runtime system will ensure this automatically.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Static constructors in superclass are always executed automatically&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;before any static constructor in subclass is executed.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Comment out the following and see what happens&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    super-&amp;gt;constructor( EXPORTING im_n_o_vehicle = ims_n_o_vehicle ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    gv_vehtype = ims_vehtype.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "constructor&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;End of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.               "zl_lcl_car&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Declaring a reference variable with reference to the subclass.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;DATA z_car TYPE REF TO zl_lcl_car.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: gv_make         TYPE string,&lt;/P&gt;&lt;P&gt;      gv_model        TYPE string,&lt;/P&gt;&lt;P&gt;      gv_vehtype      TYPE string,&lt;/P&gt;&lt;P&gt;      gv_n_o_veh      TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Creating an instance of the subclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  CREATE OBJECT z_car&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Begin of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;                EXPORTING ims_vehtype     = 'Car'&lt;/P&gt;&lt;P&gt;                          ims_n_o_vehicle = '10' .&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;End of IC240107&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Accessing the public methods of superclass&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  z_car-&amp;gt;set_make( EXPORTING im_make  = 'MARUTI'&lt;/P&gt;&lt;P&gt;                             im_model = '800' ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  z_car-&amp;gt;get_make( IMPORTING  ex_make  = gv_make&lt;/P&gt;&lt;P&gt;                              ex_model = gv_model ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  z_car-&amp;gt;get_vehtype( IMPORTING ex_vehtype = gv_vehtype&lt;/P&gt;&lt;P&gt;                                ex_n_o_veh = gv_n_o_veh ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  WRITE: / 'Vehicle type :', gv_vehtype,&lt;/P&gt;&lt;P&gt;         / 'Make  :', gv_make,&lt;/P&gt;&lt;P&gt;         / 'Model :', gv_model,&lt;/P&gt;&lt;P&gt;         / 'No of ordered vehicles :', gv_n_o_veh.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Award points if found useful.&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Indrajit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jul 2007 07:39:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/oops-methodoverriding/m-p/2469058#M554860</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-04T07:39:22Z</dc:date>
    </item>
  </channel>
</rss>

