C# Programming - Constructors - Discussion
Discussion Forum : Constructors - General Questions (Q.No. 16)
16.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
class Sample
{
static Sample()
{
Console.Write("Sample class ");
}
public static void Bix1()
{
Console.Write("Bix1 method ");
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Sample.Bix1();
}
}
}
Discussion:
17 comments Page 2 of 2.
Preethi said:
1 decade ago
Constructor can be invoked as when as object is created. Thats why default constructor is invoked first.
Sridhar said:
7 years ago
Constructor will get when we create an object but in this program not create an object why?
Usha said:
1 decade ago
Please anyone tell clearly why static constructor doesn't call first?
Kirti waore said:
9 years ago
Here we not created object then how can default constructor invoke?
Pooja said:
1 decade ago
In constructor static constructor always execute first.
Greg said:
1 decade ago
The constructor is not invoked in this example.
Sumit khedkar said:
8 years ago
No need to create object.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers