Showing posts with label Can abstract class have constructors. Show all posts
Showing posts with label Can abstract class have constructors. Show all posts

Tuesday 17 January 2012

Can abstract class have constructors

Can abstract class have constructors?


Yes, an abstract class does have a constructor.
It will be called when it subclass is instantiated.

example:

abstract class bank

    {

        public bank()

        {

            Console.WriteLine("bank");

        }

       

    }

    class icici : bank

    {

        icici()

        {

            Console.WriteLine("icici");

        }

        static void Main()

        {

            bank b = new icici();



        }

    }



//Output:

when the object of icici class is created,
They will be displayed in the output.
bank
icici