Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q281: Fill in the blank: The `operator+=` function in the `Complex` class adds the real part of another `Complex` object to the current object and _______.
- A: adds the imaginary part of the other object
- B: adds a constant value
- C: multiplies the imaginary part of the other object
- D: subtracts the real part of the other object
View Answer
A
Q282: What is the benefit of using non-member functions for operator overloading, compared to friend functions?
- A: Non-member functions do not access private data, maintaining encapsulation
- B: Non-member functions are easier to implement
- C: Non-member functions provide better performance
- D: Non-member functions are always more secure
View Answer
A
Q283: Which of the following operators can be overloaded in a similar fashion to the `+` operator?
- A: `+=`
- B: `-=`, `/=`, `*=`, `|=`, `%=`
- C: `&=`, `^=`, `<<=`, `>>=`
- D: All of the above
View Answer
D
Q284: Fill in the blank: The overloaded `operator +` function for adding a `double` to a `Complex` number creates a temporary `Complex` object and returns it by _______.
- A: value
- B: reference
- C: address
- D: indirection
View Answer
B
Q285: What operator is used in C++ for stream insertion?
- A: >>
- B: <<
- C: ->
- D: *
View Answer
B
Q286: Which operator is used in C++ to extract data from an input stream?
- A: <<
- B: >>
- C: +
- D: -
View Answer
B
Q287: The default output stream in C++ is ____.
- A: A file
- B: A network socket
- C: The console
- D: A printer
View Answer
C
Q288: What is the purpose of overloading the << operator in C++?
- A: To add two numbers
- B: To display the object on the output
- C: To delete an object
- D: To compare two objects
View Answer
B
Q289: The cin and cout objects in C++ are instances of which classes?
- A: iostream and ofstream
- B: ifstream and ofstream
- C: istream and ostream
- D: ifstream and istream
View Answer
C
Q290: In C++, stream insertion << and extraction >> operators are ______.
- A: Built-in for user-defined types
- B: Overloaded in istream and ostream
- C: Only used for integers
- D: Not used for floating-point numbers
View Answer
B