<?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: Reg : constructors in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164815#M995700</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Naveen,&lt;/P&gt;&lt;P&gt;      Again I feel that your statement is debatable. I hope you've heard about the concept of runtime polymorphism - The feature by virtue of which out of many available implementations, the correct implementation is chosen by the type of instance (or to which class the instance belongs to). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets consider the same example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*-------SUPERCLASS C1 implementation--------------
 
  method CONSTRUCTOR. "super-class constructor
    ID = 1.
    write: /'assigned super'.
  endmethod.                    "constructor
.
.
.
 
*-------SUBCLASS C2 implementation--------------
  method CONSTRUCTOR. "implemented/redefined in subclass
    SUPER-&amp;gt;CONSTRUCTOR( ).
    write: /10 'assigned sub'.
    ID = 9.
    ID2 = 1.
  endmethod.                    "constructor&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the superclass constructor sets the value of ID to 1. (ID is a protected attribute of Class C1). The subclass constructor sets ID to 9.&lt;/P&gt;&lt;P&gt;If we instantiate class C1, the value of ID will be 1. If we instantiate C2, the value of ID will be 9. So the implementation (here, setting the value of ID) depends on the instance right?Hence, runtime polymorphism holds good! Don't you think so?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 Jul 2008 05:16:13 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-07-23T05:16:13Z</dc:date>
    <item>
      <title>Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164804#M995689</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;can constructors be inherited.?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 09:52:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164804#M995689</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T09:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164805#M995690</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;*No, constructors are &lt;STRONG&gt;not&lt;/STRONG&gt; inherited*. Nor are they considered virtual&lt;/P&gt;&lt;P&gt;methods. If you do not provide a constructor in class Foo, the&lt;/P&gt;&lt;P&gt;compiler will synthesize which will fail in compilation if the superclass doesn't have a&lt;/P&gt;&lt;P&gt;parameterless constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;A superclass' constructors are only available to a class through the&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;super keyword.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Also,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Constructors and methods use the keyword this quite differently. A method uses this to refer to the instance of the class that is executing the method. &lt;STRONG&gt;Static methods do not use this&lt;/STRONG&gt;; they do not belong to a class instance, so this would have nothing to reference. Static methods belong to the class as a whole, rather than to an instance. Constructors use this to refer to another constructor in the same class with a different parameter list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Mohinder Singh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 10:24:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164805#M995690</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T10:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164806#M995691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Constructors cannot be inherited. We call the constructor of superclass from subclass by using the keyword SUPER.&lt;/P&gt;&lt;P&gt;The superclass's constructor can be used without any need to change it, or the subclass can be expanded and other parametsrs will be required in constructor's signature.&lt;/P&gt;&lt;P&gt;In ABAP Objects, the constructor can only be overwritten as a part of inheritance. It can be overwritten in the sense that both the signature and implementation can be adjusted in the subclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The constructor of the direct superclass must be called within the constructor of sublasss. This is because of specialization relationship. If a constructor was defined in superclass, it contains implementations that will always be executed when an object is created in this superclass or its subclasses. However, this can only be automaticaaly ensured by runtime system if the subclass's constructor was not changed. In most cases, supplying consistent private attributes from superclass is another prerequisite to call superclass constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: IF A SUBCLASS HAS NOT CHANGED ITS CONSTRUCTOR, THE CONSTRUCTOR IS LEFT UNCHANGED AND IS ADOPTED FROM SUPERCLASS. THE IMPLEMENTATION IS THEN EXECUTED FROM THE SUPERCLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Abhijeet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 11:04:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164806#M995691</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T11:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164807#M995692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;no.&lt;/P&gt;&lt;P&gt;constructors can not be inherited,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please search in sdn by giving key word constructors..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pradeep&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 11:06:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164807#M995692</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T11:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164808#M995693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  Just have a look at this code(only the constructor part of superclass and subclass).&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  z_CLASS_CASTING.

TYPE-POOLS icon.
INCLUDE z_class.

DATA: r_plane TYPE REF TO lcl_airplane,
      r_cargo TYPE REF TO lcl_cargo_plane,
      r_passenger TYPE REF TO lcl_passenger_plane,
      plane_list TYPE TABLE OF REF TO lcl_airplane.

START-OF-SELECTION.

lcl_airplane=&amp;gt;display_n_o_airplanes( ).

CREATE OBJECT r_passenger EXPORTING
                            im_name      = 'LH BERLIN'
                            im_planetype = '747-400'
                            im_seats     = 345.

APPEND r_passenger TO plane_list.

CREATE OBJECT r_cargo EXPORTING
                        im_name      = 'US Hercules'
                        im_planetype = '747-500'
                        im_cargo     = 533.

APPEND r_cargo TO plane_list.

LOOP AT plane_list INTO r_plane.
  r_plane-&amp;gt;display_attributes( ).
ENDLOOP.
lcl_airplane=&amp;gt;display_n_o_airplanes( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INCLUDE PROGRAM&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;  Include           z_CLASS                               *
*&amp;amp;---------------------------------------------------------------------*
CLASS lcl_airplane DEFINITION.
  PUBLIC SECTION.
    CONSTANTS: pos_1 TYPE i VALUE 30.
    METHODS:
      constructor IMPORTING
                    im_name TYPE string
                    im_planetype TYPE saplane-planetype,
                  display_attributes.
    CLASS-METHODS: display_n_o_airplanes.
  PRIVATE SECTION.
    METHODS: get_technical_attributes
               IMPORTING im_type    TYPE saplane-planetype
               EXPORTING ex_weight  TYPE s_plan_wei
                         ex_tankcap TYPE s_capacity.

    DATA: name TYPE string,
          planetype TYPE saplane-planetype.

    CLASS-DATA: n_o_airplanes TYPE i.
ENDCLASS.                    "lcl_airplane DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_airplane IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_airplane IMPLEMENTATION.

  METHOD constructor.
    name      = im_name.
    planetype = im_planetype.
    n_o_airplanes = n_o_airplanes + 1.
  ENDMETHOD.                    "constructor

  METHOD display_attributes.
    DATA: weight TYPE saplane-weight,
             cap TYPE saplane-tankcap.
    WRITE: / icon_ws_plane AS ICON,
           / 'Name of airplane', AT pos_1 name,
           / 'Airplane type:', AT pos_1 planetype.
    get_technical_attributes( EXPORTING im_type    = planetype
                              IMPORTING ex_weight  = weight
                                        ex_tankcap = cap ).
    WRITE: / 'Weight:', weight,
             'Tank capacity:', cap.

  ENDMETHOD.                    "display_attributes

  METHOD display_n_o_airplanes.
    WRITE: /,/ 'Number of airplanes:',AT pos_1 n_o_airplanes
                LEFT-JUSTIFIED, /.
  ENDMETHOD.                    "display_n_o_airplanes

  METHOD get_technical_attributes.
    SELECT SINGLE weight
                  tankcap
             FROM saplane
             INTO (ex_weight, ex_tankcap)
            WHERE planetype = im_type.
    IF sy-subrc &amp;lt;&amp;gt; 0.
      ex_weight = 100000.
      ex_tankcap = 10000.
    ENDIF.
  ENDMETHOD.                    "get_technical_attributes

ENDCLASS.                    "lcl_airplane IMPLEMENTATION

*---------------------------------------------------------------------*
*       CLASS lcl_cargo_plane DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_cargo_plane DEFINITION INHERITING FROM lcl_airplane.

  PUBLIC SECTION.

    METHODS: constructor IMPORTING im_name TYPE string
                                   im_planetype TYPE saplane-planetype
                                   im_cargo TYPE scplane-cargomax.

    METHODS: display_attributes REDEFINITION.

    METHODS: get_cargo RETURNING value(re_cargo) TYPE scplane-cargomax.

  PRIVATE SECTION.
    DATA: max_cargo TYPE scplane-cargomax.

ENDCLASS.                    "lcl_cargo_plane DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_cargo_plane IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_cargo_plane IMPLEMENTATION.

  METHOD constructor.
    CALL METHOD super-&amp;gt;constructor( im_name = im_name
      im_planetype = im_planetype ).
    max_cargo = im_cargo.
  ENDMETHOD.                    "constructor

  METHOD display_attributes.
    super-&amp;gt;display_attributes( ).
    WRITE: / 'Max Cargo = ', max_cargo.
    ULINE.
  ENDMETHOD.                    "display_attributes

  METHOD get_cargo.
    re_cargo = max_cargo.
  ENDMETHOD.                    "get_cargo

ENDCLASS.                    "lcl_cargo_plane IMPLEMENTATION

*---------------------------------------------------------------------*
*       CLASS lcl_passenger_plane DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_passenger_plane DEFINITION INHERITING FROM lcl_airplane.

  PUBLIC SECTION.

    METHODS: constructor IMPORTING im_name      TYPE string
                                   im_planetype TYPE saplane-planetype
                                   im_seats     TYPE sflight-seatsmax.

    METHODS: display_attributes REDEFINITION.

  PRIVATE SECTION.
    DATA: max_seats TYPE sflight-seatsmax.



ENDCLASS.                    "lcl_passenger_plane DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_passenger_plane IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_passenger_plane IMPLEMENTATION.
  METHOD constructor.
    CALL METHOD super-&amp;gt;constructor( EXPORTING im_name = im_name
                                         im_planetype = im_planetype ).
    max_seats = im_seats.
  ENDMETHOD.                    "constructor

  METHOD display_attributes.
    super-&amp;gt;display_attributes( ).
    WRITE: / 'Max Seats = ', max_seats.
    ULINE.
  ENDMETHOD.                    "display_attributes

ENDCLASS.                    "lcl_passenger_plane IMPLEMENTATION
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 11:09:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164808#M995693</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T11:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164809#M995694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi 'abap learner',&lt;/P&gt;&lt;P&gt;   I guess u meant 'Can constructors take part in inheritance?'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;YES! is the answer. You can implement a constructor in a subclass. Anything more about this depends on whether you're talking about the instance constructor or the class constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;If its Instance constructor:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we implement an instance constructor for a subclass, before doing anything, we have to explicitly call the super class instance constructor, &lt;STRONG&gt;regardless of whether an instance constructor has been declared for the super class or not.&lt;/STRONG&gt; For this, we use the pseudo reference 'super' as below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;super-&amp;gt;constructor( ).&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*----------------------------------------------------------------------*
*       CLASS c1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C1 definition.

  public section.
    methods: M1
    , CONSTRUCTOR.
  protected section.
    data ID type I.
endclass.                    "c1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C1 implementation.
  method M1.
    write: / 'This is from method m1 - ID: ', ID.
  endmethod.                    "m1
  method CONSTRUCTOR.
    ID = 1.
    write: /'assigned super'.
  endmethod.                    "constructor
endclass.                    "c1 IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS C2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C2 definition inheriting from C1.

  public section.
    methods: M2
    , CONSTRUCTOR.
  private section.
    data ID2 type I.
endclass.                    "c1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS C2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C2 implementation.
  method M2.
    uline.
    write: /10 'This is from method m2 - ID: ', ID.
    write: /10 'This is from method m2 - ID2: ', ID2.
    uline.
  endmethod.                    "m1
  method CONSTRUCTOR.
*The following statement should be the first statement in a *subclass constructor.
    SUPER-&amp;gt;CONSTRUCTOR( ). 
    write: /10 'assigned sub'.
    ID = 9.
    ID2 = 1.
  endmethod.                    "constructor
endclass.                    "c1 IMPLEMENTATION

data C1REF type ref to C1.
data C2REF type ref to C2.

start-of-selection.
  create object C1REF.
  C1REF-&amp;gt;M1( ).
  skip 3.
  create object C2REF.
  C2REF-&amp;gt;M2( ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Class constructor/Static Constructor:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unlike the instance constructor, while implementing a Class constructor in a subclass, we DO NOT have to explicitely call the super class constructor. During the start of execution of a class constructor (say of class c5), the class constructor of its immediate superclass (say c4) is accessed automatically. ABAP runtime doesn't execute any class constructor unless it reaches the top most class in the inheritance tree (say c1) . It then executes the class constructor of the top most class, followed by that of its subclass and so on until it reaches the class which initiated the whole process (c5).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*----------------------------------------------------------------------*
*       CLASS c1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C1 definition.
  public section.
    class-methods CLASS_CONSTRUCTOR.
endclass.                    "c1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C1 implementation.
  method CLASS_CONSTRUCTOR.
    write: /'Super class created.'.
  endmethod.                    "constructor
endclass.                    "c1 IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS C2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C2 definition inheriting from C1.

  public section.
    class-methods CLASS_CONSTRUCTOR.
endclass.                    "c1 DEFINITION

*----------------------------------------------------------------------*
*       CLASS C2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class C2 implementation.
  method CLASS_CONSTRUCTOR.
    write: /10 'Subclass created.'.
  endmethod.                    "constructor
endclass.                    "c1 IMPLEMENTATION

data C2REF type ref to C2.

start-of-selection.
  create object C2REF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 11:32:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164809#M995694</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T11:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164810#M995695</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; Constructors cannot be inherited to the subclass. It can only be called within the subclass using super to initialize the members of super class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Naveen Kumar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 11:51:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164810#M995695</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T11:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164811#M995696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Naveen,&lt;/P&gt;&lt;P&gt;    You seem to have forgotten one thing. I don't think - &lt;EM&gt;"It can only be called from the subclass"&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;    In fact, it can be implemented in the subclass, or in correct terms, redefined in the subclass, thus allowing some polymorphism. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*-------CLASS C1 implementation--------------

  method CONSTRUCTOR. "super-class constructor
    ID = 1.
    write: /'assigned super'.
  endmethod.                    "constructor
.
.
.

*-------CLASS C2 implementation--------------
  method CONSTRUCTOR. "implemented/redefined in subclass
    SUPER-&amp;gt;CONSTRUCTOR( ).
    write: /10 'assigned sub'.
    ID = 9.
    ID2 = 1.
  endmethod.                    "constructor&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As seen above, when the class C2 is instantiated, the subclass constructor overrides the superclass constructor. Thus, value of ID will be 9 and not 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Correct me if i'm wrong.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 12:08:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164811#M995696</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T12:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164812#M995697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arun,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   Super class Constructor cannot be implemented/redefined in a subclass since you are calling super class constructor within sub class constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Naveen Kumar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 12:36:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164812#M995697</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T12:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164813#M995698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see a point in that, since we're explicitly calling the super class constructor no matter what. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In that case, I don't see polymorphism there. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But at the same time, in my example, when the subclass is instantiated, it assigns a different value (9) to the super class protected variable (ID). Doesn't it smell like redefinition there?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, thanks for pointing out that vital point.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2008 13:01:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164813#M995698</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-21T13:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164814#M995699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arun,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   Using OO ABAP we cannot implement polymorphism(overloading/overriding) using constructors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Naveen Kumar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2008 07:15:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164814#M995699</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-22T07:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164815#M995700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Naveen,&lt;/P&gt;&lt;P&gt;      Again I feel that your statement is debatable. I hope you've heard about the concept of runtime polymorphism - The feature by virtue of which out of many available implementations, the correct implementation is chosen by the type of instance (or to which class the instance belongs to). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets consider the same example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*-------SUPERCLASS C1 implementation--------------
 
  method CONSTRUCTOR. "super-class constructor
    ID = 1.
    write: /'assigned super'.
  endmethod.                    "constructor
.
.
.
 
*-------SUBCLASS C2 implementation--------------
  method CONSTRUCTOR. "implemented/redefined in subclass
    SUPER-&amp;gt;CONSTRUCTOR( ).
    write: /10 'assigned sub'.
    ID = 9.
    ID2 = 1.
  endmethod.                    "constructor&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the superclass constructor sets the value of ID to 1. (ID is a protected attribute of Class C1). The subclass constructor sets ID to 9.&lt;/P&gt;&lt;P&gt;If we instantiate class C1, the value of ID will be 1. If we instantiate C2, the value of ID will be 9. So the implementation (here, setting the value of ID) depends on the instance right?Hence, runtime polymorphism holds good! Don't you think so?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2008 05:16:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164815#M995700</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-23T05:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164816#M995701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arun,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  It is not actually implemented/redefined in subclass. Both Sub class and super class constructors are independent entities. Please recollect in C++ constructor name is same as class name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Naveen Kumar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2008 14:24:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164816#M995701</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-23T14:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164817#M995702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This message was moderated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2008 05:53:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164817#M995702</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-24T05:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164818#M995703</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;I came to a coclusion that Constructors can be inherited&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;check this simple example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS cl_lc DEFINITION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;    DATA: a TYPE i,&lt;/P&gt;&lt;P&gt;          b TYPE i,&lt;/P&gt;&lt;P&gt;          c TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    METHODS: display,&lt;/P&gt;&lt;P&gt;             mm1,&lt;/P&gt;&lt;P&gt;             CONSTRUCTOR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    CLASS-METHODS: mm2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "CL_LC DEFINITION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*CLASS IMPLEMENTATION&lt;/P&gt;&lt;P&gt;CLASS cl_lc IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD display.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'THIS IS SUPER CLASS' COLOR 7.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "DISPLAY&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD mm1.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'THIS IS MM1 METHOD IN SUPER CLASS'.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "MM1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD mm2.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'THIS IS THE STATIC METHOD' COLOR 2.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'THIS IS MM2 METHOD IN SUPER CLASS' COLOR 2.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "MM2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  method CONSTRUCTOR.&lt;/P&gt;&lt;P&gt;    write :/ 'I am in Constructor'.&lt;/P&gt;&lt;P&gt;   endmethod.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "CL_LC IMPLEMENTATION&lt;/P&gt;&lt;P&gt;*SUB CLASS FUNCTIONALITY&lt;/P&gt;&lt;P&gt;*CREATE THE CLASS.&lt;/P&gt;&lt;P&gt;*INHERITING THE SUPER CLASS.&lt;/P&gt;&lt;P&gt;CLASS cl_sub DEFINITION INHERITING FROM cl_lc. "HOW WE CAN INHERIT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PUBLIC SECTION.&lt;/P&gt;&lt;P&gt;    DATA: a1 TYPE i,&lt;/P&gt;&lt;P&gt;          b1 TYPE i,&lt;/P&gt;&lt;P&gt;          c1 TYPE i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    METHODS: display REDEFINITION,     "REDEFINE THE SUPER CLASS METHOD&lt;/P&gt;&lt;P&gt;             sub.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "CL_SUB DEFINITION&lt;/P&gt;&lt;P&gt;*CLASS IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS cl_sub IMPLEMENTATION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD display.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'THIS IS THE SUB CLASS OVERWRITE METHOD' COLOR 3.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "DISPLAY&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  METHOD sub.&lt;/P&gt;&lt;P&gt;    WRITE:/ 'THIS IS THE SUB CLASS METHOD' COLOR 3.&lt;/P&gt;&lt;P&gt;  ENDMETHOD.                    "SUB&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDCLASS.                    "CL_SUB IMPLEMENTATION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*CREATE THE OBJECT FOR SUB CLASS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: obj TYPE REF TO cl_sub.&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;P&gt;  CREATE OBJECT obj.&lt;/P&gt;&lt;P&gt;  CALL METHOD obj-&amp;gt;display. "THIS IS SUB CLASS METHOD&lt;/P&gt;&lt;P&gt;  CALL METHOD obj-&amp;gt;sub.&lt;/P&gt;&lt;P&gt;  WRITE:/'THIS IS THE SUPER CLASS METHODS CALLED BY THE SUB CLASS OBJECT'COLOR 5.&lt;/P&gt;&lt;P&gt;  SKIP 1.&lt;/P&gt;&lt;P&gt;  CALL METHOD obj-&amp;gt;mm1.     "THIS IS SUPER CLASS METHOD&lt;/P&gt;&lt;P&gt;  CALL METHOD obj-&amp;gt;mm2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2008 07:06:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164818#M995703</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-24T07:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reg : constructors</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164819#M995704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bingo! There u are abaplearner!!&lt;/P&gt;&lt;P&gt;Naveen, I understand what you are saying. Agree with you. But what I am trying to say is that, we can actually simulate a redefinition here. Hope you tried out the example in my previous post.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2008 14:12:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-constructors/m-p/4164819#M995704</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-28T14:12:43Z</dc:date>
    </item>
  </channel>
</rss>

