Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

calling super class constructure

Former Member
0 Kudos
119

Hi,

I have created two classes, class A and sub class- classB, using class builder how can I call consture of super class A .

getting following error - In the constructor method, you can only access instance attributes

after the constructor of the superclass (SUPER->CONSTRUCTOR) has been

called.

Thanks for you help.

jog

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
64

If your class B inherits from class A, make sure that you specify so in the attributes tab, then in the constructor of class B, make sure to call the super->constructor.

call method super->constructor( ).

Regards,

Rich Heilman

0 Kudos
64

Similar to this in a local class.



report zrich_0001.

*---------------------------------------------------------------------*
*       CLASS lcl_a DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_a definition.

  public section.
    methods: constructor.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_a IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_a implementation.

  method constructor.
    write:/ 'A constructor'.
  endmethod.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_b DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_b definition inheriting from lcl_a.

  public section.
    methods: constructor.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_b IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_b implementation.

  method constructor.
    call method super->constructor( ).
       write:/ 'b constructor'.
  endmethod.

endclass.

data: o_clb type ref to lcl_b.


start-of-selection.

  create object o_clb.

Regards,

Rich Heilman