Cristi Diaconescu Cristi Diaconescu - 1 year ago 61
C# Question

Why should constructors on abstract classes be protected, not public?

ReSharper suggests changing the accessibility of a

constructor in an
class to
, but it does not state the rationale behind this.

Can you shed some light?

Answer Source

Simply because being public makes no sense in an abstract class. An abstract class by definition cannot be instantiated directly. It can only be instantiated by an instance of a derived type. Therefore the only types that should have access to a constructor are its derived types and hence protected makes much more sense than public. It more accurately describes the accessibility.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download