What will be the output of the following code snippet?
using System;
class sample
{
public sample()
{
Console.WriteLine("constructor 1 called");
}
public sample(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2 called");
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(4);
sample t = new sample();
Console.ReadLine();
}
}
- constructor 1 called constructor 2 called
- constructor 2 called constructor 1 called
- constructor 2 called constructor 2 called
- error
Correct Answer:
constructor 2 called constructor 1 called
need an explanation for this answer? contact us directly to get an explanation for this answer