A constructor is a special method in a class used to initialize object attributes when an object is created.