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.
Vishv said:
9 years ago
Ans- Sample class Bix1 method.
The entry point of the program is main().
When we write a static constructor, this is the next block of code execute implicitly after main() either you call it or not.
The entry point of the program is main().
When we write a static constructor, this is the next block of code execute implicitly after main() either you call it or not.
Kirti waore said:
9 years ago
Here we not created object then how can default constructor invoke?
Anjali Rani said:
9 years ago
I have run the same code but I'm getting output: Sample class only.
But your output is option A. Anybody, please help me out. I didn't understand.
But your output is option A. Anybody, please help me out. I didn't understand.
Ravi said:
8 years ago
The Constructor will call at the time of object creation only and static method will call at the time of compilation. So here we are not create any object for constructor so the output is sample class only.
Sumit khedkar said:
8 years ago
No need to create object.
Sridhar said:
7 years ago
Constructor will get when we create an object but in this program not create an object why?
Nikesh Rathour said:
6 years ago
Static constructor first block of code which always executes first even main method.
The programmer does not call static constructor, because static constructor implicitly called.
The programmer does not call static constructor, because static constructor implicitly called.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers