What are practical uses of a protected constructor?

Amol Gawai picture Amol Gawai · Jun 29, 2009 · Viewed 64.9k times · Source

Why would anyone declare a constructor protected? I know that constructors are declared private for the purpose of not allowing their creation on stack.

Answer

Henk Holterman picture Henk Holterman · Jun 29, 2009

When a class is (intended as) an abstract class, a protected constructor is exactly right. In that situation you don't want objects to be instantiated from the class but only use it to inherit from.

There are other uses cases, like when a certain set of construction parameters should be limited to derived classes.