April 23, 2015

C# Oops constructor related question part 2

I have modified base class. Now we have not defined any constructor inside base class.
Is this program will compile?

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

Yes this program will compile because we have default constructor in base class.

No comments:

Post a Comment