<?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: Calling Subclass method from Super class in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422034#M1409540</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;          Only if the subclass overrides the method in superclass. Then by polymorphism we can use the subclass method.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Dec 2009 12:04:03 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-12-16T12:04:03Z</dc:date>
    <item>
      <title>Calling Subclass method from Super class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422032#M1409538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    Is it possible to call a subclass method from superclass ? If it is possible, how it can be achieved ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Padmam.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Dec 2009 09:08:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422032#M1409538</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-12-16T09:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Subclass method from Super class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422033#M1409539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To my 'rusting Java' knowledge, the visibility is always with the sub classes. In the sense, the sub class can access the methods and attributes of its super classes. The super class will not have any clue as to which classes have extended it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Dec 2009 09:29:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422033#M1409539</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-12-16T09:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Subclass method from Super class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422034#M1409540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;          Only if the subclass overrides the method in superclass. Then by polymorphism we can use the subclass method.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Dec 2009 12:04:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422034#M1409540</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-12-16T12:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Subclass method from Super class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422035#M1409541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Halo Padmam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A super class reference variable can hold a subclass reference variable . This superclass can call methods which are defined in the superclass only . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you can do is cast the superclass reference  variable to Subclass reference variable and call the method as explained in Case 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See for eg&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;data lr_animal type ref to zanimal.&lt;/P&gt;&lt;P&gt;data lr_lion type ref to zlion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here zlion is a subclass of zanimal. It is possible to assign zlion to zanimal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create object lr_lion.&lt;/P&gt;&lt;P&gt;create object lr_animal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First Case&lt;/P&gt;&lt;P&gt;lr_animal =  lr_lion.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now when you try to call method which is specific to lion it will not allow .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second Case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can assign a super class reference variable to a subclass reference variable&lt;/P&gt;&lt;P&gt;you need to use the casting operator for the same&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lr_lion ?= lr_animal.&lt;/P&gt;&lt;P&gt;Now you can use lr_lion to call lion specific method&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Arshad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Dec 2009 12:12:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422035#M1409541</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-12-16T12:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Subclass method from Super class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422036#M1409542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your object reference refers to an instance of the subclass and the method is redfined in the subclass, the subclass implementation of the method will be called, even if the method is called from another method in the base class. The exception is when the method is called during creation (i.e. from the contructor or a mehods called from the contructor). In this case the baseclass implementation is called.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  ztest.

*----------------------------------------------------------------------*
*       CLASS lcl_base DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_base DEFINITION.
  PUBLIC SECTION.
    METHODS:
      constructor,
      m1,
      m2.
ENDCLASS.                    "lcl_base DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_base IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_base IMPLEMENTATION.
  METHOD constructor.
    m2( ).
  ENDMETHOD.                    "constructor

  METHOD m1.
    m2( ).
  ENDMETHOD.                    "m1

  METHOD m2.
    WRITE / 'lcl_base=&amp;gt;m2'.
  ENDMETHOD.                    "m2
ENDCLASS.                    "lcl_base IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS lcl_sub DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_sub DEFINITION INHERITING FROM lcl_base.
  PUBLIC SECTION.
    METHODS:
      constructor,
      m2 REDEFINITION.
ENDCLASS.                    "lcl_sub DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_sub IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_sub IMPLEMENTATION.
  METHOD constructor.
    super-&amp;gt;constructor( ).
  ENDMETHOD.                    "constructor

  METHOD m2.
    WRITE / 'lcl_sub=&amp;gt;m2'.
  ENDMETHOD.                    "m2
ENDCLASS.                    "lcl_sub IMPLEMENTATION

DATA o TYPE REF TO lcl_base.

START-OF-SELECTION.

  CREATE OBJECT o TYPE lcl_sub.
  o-&amp;gt;m1( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output of this program is:&lt;/P&gt;&lt;P&gt;lcl_base=&amp;gt;m2&lt;/P&gt;&lt;P&gt;lcl_sub=&amp;gt;m2 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first call to m2 is during creation, which results in a call to lcl_base=&amp;gt;m2. The second call lcl_sub=&amp;gt;m2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/Christoffer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Dec 2009 12:17:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422036#M1409542</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-12-16T12:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Subclass method from Super class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422037#M1409543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should not call the Subclass method from the Super Class. If you ever need to do this, you can create the "Agent" class and let the Agent class handle all the calls. You can decide in the Agent class, which method you need to call i.e. from Subclass or Superclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Dec 2009 15:58:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-subclass-method-from-super-class/m-p/6422037#M1409543</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2009-12-16T15:58:45Z</dc:date>
    </item>
  </channel>
</rss>

