Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q241: In the provided `String` class, what does the overloaded constructor with `char *` as a parameter do?
- A: Initializes the string with the given char array
- B: Deletes the string
- C: Initializes the string with default value
- D: Returns the string
View Answer
A
Q242: In the `Student` class, what is the purpose of the `GetNamePtr` method?
- A: To return the pointer to the student's name
- B: To set the student's name
- C: To delete the student's name
- D: To display the student's name
View Answer
A
Q243: The `Date` class is used in the `Student` class to store which information?
- A: Student's birth date
- B: Student's ID
- C: Student's GPA
- D: Student's name
View Answer
A
Q244: What is the purpose of operator overloading in C++?
- A: It allows creating new operators
- B: It allows using existing operators for user-defined types
- C: It changes the precedence of operators
- D: It creates new data types
View Answer
B
Q245: Which of the following operators cannot be overloaded in C++?
- A: +
- B: ?
- C: -
- D: *
View Answer
B
Q246: What is the correct way to overload the + operator as a member function in C++?
- A: Complex operator +(const Complex & rhs);
- B: Complex& operator +(const Complex & rhs);
- C: void operator +(const Complex & rhs);
- D: Complex operator +(const Complex & rhs) const;
View Answer
D
Q247: In the statement `Complex c3 = c1 + c2 + c3 + c4;`, how does operator overloading affect the expression?
- A: The expression is evaluated from right to left
- B: The expression is evaluated from left to right
- C: The expression is evaluated based on operator precedence
- D: The expression cannot be evaluated if operators are overloaded
View Answer
B
Q248: Which operator is used in C++ to overload operators as a non-member function?
- A: operator
- B: ::
- C: friend
- D: &
View Answer
A
Q249: What is a common drawback of using a void return type for overloaded operators?
- A: It is less readable and maintainable
- B: Operators cannot be overloaded with void return type
- C: It increases debugging time
- D: It changes operator precedence
View Answer
A
Q250: Fill in the blank: To overload the binary + operator for a class, the function must have at least one formal parameter of type _______.
- A: primitive type
- B: class type
- C: int
- D: type
View Answer
A