Question: What is the role of a constructor in object-oriented programming?Answer: A constructor initializes an object's state and is called when an object is created. It typically assigns values to the object's attributes.Example:
|
Is it helpful?
Yes
No
Most helpful rated by users:
- What is the difference between a stack and a queue?
- What is the purpose of an index in a database?
- What is the purpose of the \'git\' version control system?