I'm studying C#. I have some concerns about the abstract class. abstract class does not allow to create instance. Why does c# support constructor for abstract class. What is the main purpose here?
2 Answers
Because an abstract class can still have things it needs to initialise as part of its construction, and although it can't be instantiated directly, it will still be constructed as part of the inheriting type being instantiated, and so still needs that degree of creation control for its self and concerns.

- 44,454
- 10
- 85
- 129
The classes that derive from your abstract
class will need an instance constructor to "chain" from their constructors.
As Grant says, your constructor of the abstract class might setup a lot of ("concrete") state that your abstract class may have.
Note: The instance constructors of an abstract type should never be public
. That would be confusing, for the reasons in your question. Make them protected
instead (or possibly internal
(not protected internal
) or private
).
If you don't write any instance constructors explicitly, the compiler will generate a "default" constructor for you, and that will be protected
for an abstract class.

- 60,409
- 11
- 110
- 181