To customize how a class initializes its members , or to invoke functions when an object of your class is created, define a constructor. … Typically, constructors have public accessibility so that code outside the class definition or inheritance hierarchy can create objects of the class.