A __________ is a special method used to initialize the instance variable of a…
2009
A __________ is a special method used to initialize the instance variable of a class.
- A.
Member function
- B.
Destructor
- C.
Constructor
- D.
Structure
Show answer & explanation
Correct answer: C
Concept
A constructor is a special member function of a class that the compiler or runtime invokes automatically the moment an object of that class is created. Its defining job is to set up the object's initial state - specifically, to initialize the instance variables (data members) to valid starting values - and it does so without ever being called explicitly by the programmer.
Application
The blank in the stem describes exactly this role: "a special method used to initialize the instance variable of a class." Among the four options, only the constructor is a method whose specific purpose is instance-variable initialization at object-creation time, so it is the term that completes the sentence correctly.
Contrast
Member function - the general category covering any function declared inside a class to operate on or with its data; most member functions are invoked explicitly by name for a specific operation, unlike the automatically-invoked role the blank describes.
Destructor - a special method invoked automatically when an object is destroyed (goes out of scope or is deallocated); its job is releasing resources, not initializing them.
Structure - a user-defined composite data type used to group related variables under one name; it is a data-type declaration, not the special initialization method the blank refers to.