2008 Apr 16 1:35 PM
2008 Apr 16 1:37 PM
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.
2008 Apr 16 1:37 PM
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.
2008 Apr 16 1:38 PM
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
2008 Apr 16 1:39 PM
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.
2008 Apr 16 1:49 PM
HI,
In simple words, Constructor will allocate memory to the instance of the class. Its an method in Object Orientation.
Thanks,
Sriram Ponna.