Application Development and Automation 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: 
Read only

Constructor-OOP

former_member260552
Active Participant
0 Likes
742

Newbie question....

In both super class and subclass i am using constructor.The problem is arising when i am creating objects.The main constructor is being initialized twice,once there when super class object creating and another due to mandatory addition of "super->constructor" in subclass constructor method.How can i make sure that the super class constructor does not initialize twice.

4 REPLIES 4
Read only

SharathYaralkattimath
Contributor
0 Likes
678

Make your superclass constructor as protected, now only your subclass can call the super class constructor & you cannot create object of superclass.

Read only

0 Likes
678

Hi Sharath

Tried but Constructor can't be declared in protected section.It is not possible.

This is a point in ABAP WORKBENCH TAW12 Part 1 book.

A constructor must be defined in the public area.

Read only

0 Likes
678

Till Release 7.0 EhP2, CONSTRUCTOR can only be declared as Public. From this release onwards, we can define the CONSTRUCTOR visibility also while defining the class.

Read only

Former Member
0 Likes
678

Put condition on '' super->constructor '' in subclass constructor if you dont want to call it twice.

check if the super class object already created or set a flag if constructor already called.


Hope i solved your problem.