Tuesday, March 26, 2013

Sub Class Inherits Constructor of Super Class


Constructor of Super class is Inherited by its Sub classes. Hence super class needs not to be instantiated in the data processing to fetch the functionality of the constructor.

We have derived a program where we have defined a parent class and a constructor in the public section. Then we implement that constructor in the implementation portion. Next we define child class inheriting from parent class. Now in the start of selection when we create the object of child class then the constructor method is called automatically and we get the functionality implemented in that constructor. Hence we are not creating any object for the parent class but we can get its constructor. Here we are getting the constructor of super class by creating the object of sub class.


REPORT  zsr_test NO STANDARD PAGE HEADING.

*----------------------------------------------------------------------*
*       CLASS test DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS test DEFINITION.
  PUBLIC SECTION.
    DATA v_test TYPE char40.
    METHODS constructor.
ENDCLASS.                    "test DEFINITION

*----------------------------------------------------------------------*
*       CLASS test IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS test IMPLEMENTATION.
  METHOD constructor.
    v_test = 'SAP ABAP Object Oriented'.
    WRITE: / v_test.
  ENDMETHOD.                    "constructor
ENDCLASS.                    "test IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS child DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS child DEFINITION INHERITING FROM test.
ENDCLASS.                    "child DEFINITION

*----------------------------------------------------------------------*
*       CLASS child IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS child IMPLEMENTATION.
ENDCLASS.                    "child IMPLEMENTATION

START-OF-SELECTION.
  DATA obj TYPE REF TO child.
  CREATE OBJECT obj.

Below is the output:

7 comments:

yektek training said...

nice post thanks for sharing from Swathi

siva sankar Sankar said...

excellent post thanks for sharing from Sankar

simashree said...

Thank you for such guidance about astrology,Best Blog on Astrology Services in Chennai

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

http://thecreatingexperts.com/sap-mm-training-in-chennai/

suganya said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!