SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

Object Oriented Programming in ABAP - Inheritance - Constructors of superclass flows down the chain

Object Oriented Programming in ABAP - Inheritance - Constructors of superclass flows down the chain

Constructor of superclass is inherited by the subclass also.

Class C1 contains a constructor method, but its subclass C2 does not explicitly have its own.

When object from class C2 is created, the constructor of class C1 is triggered.

This establishes the theme.



REPORT zstp_oo_abap.

CLASS c1 DEFINITION.
  PUBLIC SECTION.
    METHODS :  constructor .
ENDCLASS.

CLASS c1 IMPLEMENTATION.

  METHOD constructor.
    WRITE:/5 'I am C1'.
    SKIP.
  ENDMETHOD.
ENDCLASS.

CLASS  c2 DEFINITION INHERITING FROM c1.
ENDCLASS.

CLASS  c2 IMPLEMENTATION.
ENDCLASS.


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

Output -

Inheritance - Constructors of superclass flows down the chain

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in