Can our abstract class have Constructor?
If yes,Then how to call them?
Cheers
Abstract Class
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Sep 11, 2013, 4:28 AM EDT
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.
Joxin Stanly181 reputationPosted Sep 11, 2013, 3:59 AM EDT
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){}
}
Suthish NairRank #92 · 22.8K reputationPosted Sep 13, 2013, 1:11 AM EDT
Abhineet SrivastavaRank #1,890 · 783 reputationPosted Sep 13, 2013, 1:20 AM EDT