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: 

constructor

Former Member
0 Kudos
102

dear exparts

what is constructor?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
73

Hi,

a constructor in a class is a special block of statements called when an object is created

Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.

The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.

The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.

rgds,

bharat.

4 REPLIES 4

Former Member
0 Kudos
74

Hi,

a constructor in a class is a special block of statements called when an object is created

Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.

The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.

The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.

rgds,

bharat.

Former Member
0 Kudos
73

Hi Frd

Constructor:The constructor method is called automatically when you instantiate the class ( create object statement). You generally pass the parameters of the method in the create object statement.

The constructor creates, initializes, and positions the control.

Example:create object docking_container

exporting

parent = parent

dynnr = dynnr

repid = repid

side = side

extension = extension

style = style

lifetime = lifetime

metric = metric

caption = caption

no_autodef_progid_dynnr = no_autodef_progid_dynnr

exceptions

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5.

Reward Me Points

By

Pari

Former Member
0 Kudos
73

Hi,

Constructor method

Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.

The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.

The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.

Static constructor

The static constructor is always called CLASS_CONSTRUCTER, and is called autmatically before the clas is first accessed, that is before any of the following actions are executed:

1) Creating an instance using CREATE_OBJECT

2) Adressing a static attribute using <classname>-><attrbute>

3) Calling a ststic attribute using CALL METHOD

4) Registering a static event handler

5) Registering an evetm handler method for a static event

The static constructor cannot be called explicitly.

Thanks.

Former Member
0 Kudos
73

HI,

In simple words, Constructor will allocate memory to the instance of the class. Its an method in Object Orientation.

Thanks,

Sriram Ponna.