In the context of object-oriented programming, which of the following options…
2025
In the context of object-oriented programming, which of the following options accurately describes a constructor in a class?
Answer: C. A member function that shares the class name and is automatically invoked during object creation — A constructor is a special method used to initialize objects when they are created.
- A.
A method that returns a value and must be explicitly called to initialize variables
- B.
A predefined static block executed before any method or field of the class
- C.
A member function that shares the class name and is automatically invoked during object creation
- D.
A special function used to allocate memory dynamically for class instances
Attempted by 240 students.
Show answer & explanation
Correct answer: C
A constructor is a special method used to initialize objects when they are created.