Tuesday, August 12, 2014

C# Base

    class Program
    {
        static void Main(string[] args)
        {
            B b = new B();
            Console.Read();
        }
    }

    class A
    {
        internal int x = 10;
        public int MyProperty { get; set; }
        public A()
        {          
            Console.WriteLine("A Constructor");
        }
    }

    class B:A
    {
        public B(): base()
        {                
            Console.WriteLine("B Constructor ");
        }
    }

What's the output of the above program?

Note: base keyword can be used ONLY from derived class's constructor to access base class members (non-private members)

No comments: