Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

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:

Java constructor: 'public MyClass(int value) { this.value = value; }'
Is it helpful? Yes No

Most helpful rated by users:

©2025 WithoutBook