Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q291: The correct syntax for overloading the << operator as a friend function in C++ is:
- A: ostream& operator<<(ostream &os, const Complex &c)
- B: istream& operator<<(istream &os, const Complex &c)
- C: void operator<<(ostream &os)
- D: Complex& operator<<(Complex &c)
View Answer
A
Q292: When overloading the >> operator for a class, the function should return a reference to ______.
- A: ostream
- B: istream
- C: ofstream
- D: ifstream
View Answer
B
Q293: Overloading the == operator in C++ allows us to:
- A: Compare two objects for equality
- B: Add two objects
- C: Subtract two objects
- D: Multiply two objects
View Answer
A
Q294: Overloading the != operator in C++ allows us to:
- A: Add two objects
- B: Multiply two objects
- C: Compare two objects for inequality
- D: Subtract two objects
View Answer
C
Q295: When using the << operator for user-defined data types, you must ______.
- A: Use a default operator
- B: Overload the operator
- C: Avoid using the operator
- D: Use the operator directly
View Answer
B
Q296: To handle multiple input operations in a single line in C++, the stream extraction operator is ______.
- A: overloaded
- B: not required
- C: used only with integers
- D: used only with strings
View Answer
A
Q297: In C++, what is the output for the following code? cout << c1 << endl << c2;
- A: (1.01, 20.1) (0.01, 12.0)
- B: (1.01, 20.1)
- C: (1.01) (0.01, 12.0)
- D: (0.01, 12.0)
View Answer
A
Q298: The comparison operator == is typically overloaded as a ______ function.
- A: non-member
- B: member
- C: static
- D: inline
View Answer
B
Q299: Which of the following is a limitation of overloading the << operator as a member function?
- A: Difficult syntax
- B: Cascaded statements not possible
- C: Requires special syntax
- D: Both A and B
View Answer
D
Q300: In C++, which operator is overloaded to allow cascading operations?
- A: +
- B: *
- C: <<
- D: >>
View Answer
C