What is the primary purpose of a constructor in a class? 

  • To delete instances of a class. 
  • To declare variables. 
  • To initialize object properties. 
  • To control memory allocation.
A constructor is a special member function of a class that is executed whenever a new object of that class is created. Its primary role is to initialize the attributes or properties of the class, ensuring that the object starts its life in a controlled state.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *