Constructors for Abstract Types

You want to know how to implement constructors in abstract types.

Assign a protected scope to constructors for abstract classes.

Give constructors in abstract classes protected visibility since they are intended only to be called by derived types. The C# compiler will automatically create a protected constructor in abstract classes for you. However, it’s recommended that you explicitly define one.


// OK. The default constructor is appropriately handled by the compiler.
public abstract class File {

// The recommended approach. The constructor is explicitly defined.
public abstract class File {
    // Leave the constructor empty.
    protected File() {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s