The term constructor is used in object-oriented programming (OOP). A constructor is a method that creates an object and/or initializes its attributes. A constructor that creates objects must be defined as a class method
, while theconstructor that initializes only the attributes of an object can also be defined as an instance method
. The opposite mechanism to the constructor is the destructor.