Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q261: What does the `Complex operator + (const double& rhs)` function do?
- A: It adds a double value to a complex number and returns the result
- B: It adds two complex numbers
- C: It subtracts a double value from a complex number
- D: It multiplies a complex number by a double value
View Answer
A
Q262: What is the issue with the statement `Complex c5 = 450.120 + c1` when adding a double to a complex number?
- A: The `+` operator is called with reference to the double value
- B: The `+` operator is not overloaded for the double type
- C: The `+` operator cannot handle complex number arguments
- D: The `+` operator results in a compilation error
View Answer
A
Q263: How can adding a complex number to a real number (or vice versa) be handled in C++?
- A: By overloading the `+` operator as a non-member function
- B: By using a member function only
- C: By using a static function
- D: By using a global function
View Answer
A
Q264: What is the main benefit of overloading the assignment operator in classes with dynamic memory?
- A: It prevents memory leaks and dangling pointers
- B: It allows multiple assignments in a single statement
- C: It optimizes performance
- D: It changes the data type of the assigned values
View Answer
A
Q265: In the context of operator overloading, what does the term "deep copy" refer to?
- A: Copying the value of members individually
- B: Creating a new object for each assignment
- C: Performing a shallow copy of the object
- D: Assigning the same reference to multiple objects
View Answer
A
Q266: What problem occurs with the statement `str1 = str2 = str3` when the assignment operator is void?
- A: The assignment is executed in reverse order, leading to errors
- B: The void return type causes issues with chaining assignments
- C: The assignment operator cannot handle multiple assignments
- D: The void return type causes compilation errors for all assignments
View Answer
B
Q267: To resolve the issue with chaining assignments, what change should be made to the assignment operator?
- A: It should return a reference to the current object
- B: It should return a new object
- C: It should handle multiple types
- D: It should not use the `void` return type
View Answer
A
Q268: Fill in the blank: The `operator+` function for a complex number and a double can be implemented as a _______ function to handle operations involving basic data types.
- A: friend
- B: member
- C: static
- D: global
View Answer
A
Q269: What type of operator function is needed to add a complex number and a double value using a friend function?
- A: Binary operator function
- B: Unary operator function
- C: Ternary operator function
- D: Static operator function
View Answer
A
Q270: In the modified assignment operator code, what is the purpose of the `delete [] bufferPtr` statement?
- A: It resolves inaccessible memory issues by deallocating old memory
- B: It initializes the buffer pointer to NULL
- C: It allocates new memory for the buffer
- D: It copies the old buffer to the new buffer
View Answer
A