Interviews12 answers
Constructor is possible in abstract class ?
12 Answers
Yes It is possible..
Akhilesh TiwariPosted Jan 4, 2017, 1:06 AM EST
yes
Manoj Kumar DuraisamyPosted Jan 2, 2017, 8:52 PM EST
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 YadavPosted Dec 21, 2016, 12:09 AM EST
no
Hiren ParmarPosted Aug 14, 2016, 9:22 PM EDT
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 PandeyPosted Jun 12, 2016, 9:25 PM EDT
Abstract has private constructor.
Sunil BabuPosted Apr 2, 2016, 3:28 AM EDT
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 VenkatesanPosted Mar 31, 2016, 4:30 AM EDT
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 kvPosted Mar 10, 2016, 3:43 AM EST
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 SaiPosted Feb 17, 2016, 3:06 AM EST
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 SaiPosted Feb 17, 2016, 3:03 AM EST
no
Mohsen GoodarziPosted Feb 2, 2016, 12:11 PM EST
yes.
abstract class MyClass
{
public MyClass(int x)
{
}
}
Rajesh SinghPosted Nov 16, 2015, 5:45 AM EST





