1. What is a constructor in an object-oriented class?
A constructor is a special method of a class that is called when a new object is created. Its job is to initialize the new object’s state—setting up fields, allocating resources, or performing setup tasks so that the object is ready to use.