Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q141: What should you do in a destructor to prevent memory leaks?
- A: Free the memory allocated using new
- B: Reallocate memory
- C: Call the copy constructor
- D: Perform no action
View Answer
A
Q142: Which of the following is not true about the this pointer?
- A: It is a pointer to the current object
- B: It is automatically passed to member functions
- C: It can be used to access static members
- D: It helps in differentiating between member variables and parameters
View Answer
C
Q143: What does the setRollNo function do in the given example?
- A: It sets the roll number with error checking
- B: It retrieves the roll number
- C: It deletes the roll number
- D: It prints the roll number
View Answer
A
Q144: Fill in the blank: The ~Student function in a class is known as the _____ function.
- A: destructor
- B: constructor
- C: accessor
- D: mutator
View Answer
A
Q145: What will happen if you delete an object with dynamic memory without proper deep copying?
- A: The memory allocated for dynamic members may be freed and lead to dangling pointers
- B: The object will be recreated
- C: The memory will be reallocated automatically
- D: Nothing, as it does not affect dynamic memory
View Answer
A
Q146: Fill in the blank: The copy constructor is called when an object is _____ to another object.
- A: assigned
- B: initialized
- C: deleted
- D: copied
View Answer
D
Q147: What is an important point to remember about copy constructors?
- A: They perform deep copying when dynamic memory is involved
- B: They perform shallow copying always
- C: They do not affect memory management
- D: They are not necessary for classes with dynamic memory
View Answer
A
Q148: What is the purpose of the this pointer in C++?
- A: Return the address of the class
- B: Return reference to the current object
- C: Return reference to a static object
- D: Return the address of a method
View Answer
B
Q149: Which method can be used to implement method chaining in C++?
- A: Using const keyword
- B: Using this pointer
- C: Using static methods
- D: Using virtual methods
View Answer
B
Q150: What does return *this; in a member function indicate?
- A: Returning the address of the current object
- B: Returning a copy of the current object
- C: Returning a reference to the current object
- D: Returning a pointer to the method
View Answer
C