Can our abstract class have Constructor?
If yes,Then how to call them?
Cheers
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Sep 11, 2013, 8:28 AM
Note that even if you provide an abstract class with a public or internal constructor, you still can't create an instance of it for obvious reasons.
Abhineet SrivastavaPosted Sep 13, 2013, 5:20 AM
Suthish NairPosted Sep 13, 2013, 5:11 AM
Joxin StanlyPosted Sep 11, 2013, 7:59 AM
It provide a standard way to instantiate data in the abstract class. That way you can have classes that inherit from that class call the base constructor.
public abstract class A
{
private string data;
protected A(string myString)
{
data = myString;
}
}
public class B : A
{
B(string myString) : base(mystring){}
}