Constructor and Destructor – C# Programming Questions – Real

(Last Updated On: January 20, 2017)

This section contains technical C# programming interview questions on constructor and destructor with answers and explanation asked in technical interviews for freshers and experienced.

Topic – Constructor and Destructor, Static Constructor in C#, Private constructors etc.


Q- What is output of the following program? When we create 2 objects of the class A e.g.

A obj1 = new A();
A obj2 = new A();

Answer:

Output:

Static Constructor
Class Constructor
Class Constructor

 

Explanation: If we have static constructor in a class, it will be called before class constructor when we create first object of the class.

Static constructor will be called only once i.e. on first object creation and will not be called even we create multiple objects afterwards.

That’s the reason, in the output Static Constructor is called on first object creation.