questions on classes and constructors

Posted by Gayathri under C# on 3/3/2010 | Views : 2144 | Status : [Member] | Replies : 2
1) difference between static constructor, private constructors and abstract classes as well please clarify sealed classes?
i have come across through many articles, but it will be helpful if you anybody can give a best example like where and when to use them.

2) what is constructor chaining?


Posted by: Abhi2434 on: 3/4/2010 [Member] [Microsoft_MVP] [MVP] Silver

These are really basic questions..

Well, static constructors are called once when application starts. It is helpful to initialize static variables and call static methods.

Private constructors is not often used. It actually restricts objects to be created only from within nested classes and you cant use the constructor to create objects from outside.

Abstract classes are those which have few methods declared and undefined. So abstract classes can also cannot be initialized.

Sealed classes cannot be inherited.

I hope you are clear now.

Constructor chaining means calling another constructor from within a constructor:

public Chaining(int a, int b) : this(a)

something like this, as it calls
public Chaining(int a)



from the other constructor.

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srikrishna777 on: 3/9/2010 [Member] Starter

Hi Gayathri,

we can have static constructors.This constructor will be called only one time.A general constructor will be called when ever an object is created .so,If there n objects,n times general constructor will be called.But ,Static constructor will be called only once even when we have more no.of objects and these constructors cant be overloaded too.


Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response