Should Constructors Be Public?

No, Constructors can be public , private , protected or default (no access modifier at all). Making something private doesn't mean nobody can access it. It just means that nobody outside the class can access it. ... Using private constructor we can ensure that no more than one object can be created at a time.

When should a constructor be public or private?

Make the constructor public if you allow your client code outside the package instantiate your object. If you don't want that( because object is package specific or the object itself can't be instantiated directly ) use package-private.

Is constructor private or public?

A constructor is a special member function of a class which initializes objects of a class. In C++, constructor is automatically called when object of a class is created. By default, constructors are defined in public section of class.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.