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.
Showing results for 
Search instead for 
Did you mean: 

Static Cunstructor will execute first or Instance Cunstructor

Former Member
0 Kudos


Static Cunstructor will execute first or Instance Cunstructor.

Plz explain me. Its urgent.



Former Member
0 Kudos


Static Constructor will execute first , then Instance constructor.

The reason is during compile time itself the static constructor will have value..

and for instance constructor when the object gets created i.e during runtime has value..

reward if helpful..



Edited by: Briesh Patel on Apr 22, 2008 4:55 PM

Edited by: Briesh Patel on Apr 22, 2008 5:03 PM

Former Member
0 Kudos


Static constructo was executed whenever u r class is loaded. But instance constructor was executed whenever u Created the object using 'CREATE OBJECT' Statement.

Static constructor is executed first before executing the instance constructor.


Constructors are special PUBLIC methods that are triggered when an object is instantiated from a class. They are necessary when you want to set the initial state of an object dynamically.

Like normal methods, there are two types of constructor - instance constructors and static constructors.

To use the instance constructor, the CONSTRUCTOR method must be declared in the public section of the class using the METHODS statement, and implemented in the implementation section.

Constructors must always be declared in the PUBLIC section of a class.

Instance Constructor:

1)Executed once for each instance.

2)Called automatically, immediately after the CREATE OBJECT statement.

3)Can contain an interface with IMPORTING parameters and EXCEPTIONS , but cannot have any EXPORTING/CHANGING/RETURNING parameters .

4)The interfaces are defined using the same syntax as for normal methods in the METHODS statement. To transfer parameters and handle exceptions, use the EXPORTING and EXCEPTIONS additions to the CREATE OBJECT statement .

Static Constructor:

1)Static methods, declared as CLASS-METHODS : CLASS_CONSTRUCTOR in the public section of the class definition and are also implemented in the implementation part.

2)Has no interface parameters and cannot trigger exceptions.

3)Executed once in each program. It is called automatically for the class before it is accessed for the first time - that is, before one of the following actions:

a)CREATE OBJECT obj from the class.

b)Call a static method : [CALL METHOD] class=>meth.

c)Registering a static event handler method using SET HANDLER class=>meth for obj.

d)Registering an event handler method for a static event of the class class.

e)Addressing a static attribute with class=>a.

If it is helpful rewards points



Former Member
0 Kudos


for more info refer



Active Participant
0 Kudos

Hello Ranveer,

The static constructor is a special static method in a class and is always named

CLASS_CONSTRUCTOR. It is executed no more than once per program (and

class). The static constructor is called automatically before the class is first

accessed, but before any of the following actions are executed for the first time:

- Creating an instance of this class (CREATE OBJECT)

- Accessing a static attribute of this class

- Calling a static method of this class

- Registering an event handler method for an event in this class

Always consider the following points when you define static constructors:

- Each class has no more than one static constructor

- The static constructor must be defined in the public area

- The constructor's signature cannot have importing parameters or exceptions

- The static constructor cannot be called explicitly