April 24, 2015

C# Oops constructor related question

What will be the output of below program

    class ConstructorConcept
    {
       
static void Main()
        {
           
ExtendedSample objExtendedSample = new ExtendedSample("Oops is very interesting");
           
Console.ReadKey();
        }

       
public class Sample
        {
         
           
public Sample(string Val)
            {
               
Console.WriteLine("I am in one argument constructor => Sample"); 
            }
        }

       
public class  ExtendedSample:Sample
        {
           
public ExtendedSample()
            {
               
Console.WriteLine("I am in zero argument constructor => ExtendedSample"); 
            }

           
public ExtendedSample(string Val)
            {
               
Console.WriteLine("I am in one argument constructor => ExtendedSample"); 
            }
        }
    }

This program will not compile because in base class we don’t have zero argument constructor.

No comments:

Post a Comment