Q:

What will be the output of the following code snippet?

0

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();
     }
}

  1. constructor 1 called constructor 2 called
  2. constructor 2 called constructor 1 called
  3. constructor 2 called constructor 2 called
  4. error

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Correct Answer:

constructor 2 called constructor 1 called

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now