12
Reply

Constructor is possible in abstract class ?

Rajesh Singh

Rajesh Singh

Nov 16, 2015
2.2k
1

    Yes, it is possible. Unlike interfaces, abstract classes do contain implementation.So to initialize its members we can use the constructor and the abstract class constructor will invoke prior to derived class constructor

    vipin kv
    March 10, 2016
    2

    Yes surely you can add one, as already mentioned for initialization of Abstract class variables. BUT if you dont explicitly declare one, it anyways has an implicit constructor for "Constructor Chaining" to work. Abstract class can have a constructor though it cannot be instantiated

    Subhashkumar Yadav
    December 21, 2016
    1

    Yeah..We can have the constructor in abstract class, below are the example-abstract class A{public int a;public A(){a = 10;} }class B : A{public int b;public B(){b = 20;}}protected void Page_Load(object sender, EventArgs e){B b1 = new B(); Response.Write(b1.a);Response.Write(b1.b);}

    Ashutosh Pandey
    June 13, 2016
    1

    You can create constructors in an abstract class - but they are not inherited. Your only choice in the derived class is which of the base class constructors you will call. You cannot declare an abstract constructor, because constructors cannot be overridden, regardless of whether the class is abstract or can be instantiated.In the abstract class, you just declare constructors as normal.

    Keerthi Venkatesan
    March 31, 2016
    1

    using System; abstract class absclass {public absclass(){Console.WriteLine("I am abstract class constructor");}public abstract void Print(); } class norClass : absclass {public norClass(){Console.WriteLine("I am derived classs constructor");}public override void Print(){Console.WriteLine("I am print method");} } class mainclass {static void Main() {norClass obj = new norClass();} }

    Sankar Sai
    February 17, 2016
    1

    yes.abstract class MyClass{public MyClass(int x){}}

    Rajesh Singh
    November 16, 2015
    1

    Yes It is possible..

    Akhilesh Tiwari
    January 04, 2017
    0

    yes

    Manoj Kumar
    January 03, 2017
    0

    no

    Hiren Parmar
    August 15, 2016
    0

    Abstract has private constructor.

    Sunil Babu
    April 02, 2016
    0

    Yes it is possible..We can point a abstract class object to a derived class. While performing this action by default abstract class constructor will get executed first. Also the legend theory of inheritance gives the answer here, parent class constructor gets executed before child class constructor. If we are using abstract class we need to implement it on derived class.

    Sankar Sai
    February 17, 2016
    0

    no

    Mohsen Goodarzi
    February 02, 2016
    0