Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 18
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
Correct Answer: A
Chapter: 18
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
Correct Answer: A
Chapter: 18
Q283:
Which of the following operators can be overloaded in a similar fashion to the `+` operator?
A. `+=`
B. `-=`, `/=`, `*=`, `|=`, `%=`
C. `&=`, `^=`, `<<=`, `>>=`
D. All of the above
Correct Answer: D
Chapter: 18
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
Correct Answer: B
Chapter: 19
Q285:
What operator is used in C++ for stream insertion?
A. >>
B. <<
C. ->
D. *
Correct Answer: B
Chapter: 19
Q286:
Which operator is used in C++ to extract data from an input stream?
A. <<
B. >>
C. +
D. -
Correct Answer: B
Chapter: 19
Q287:
The default output stream in C++ is ____.
A. A file
B. A network socket
C. The console
D. A printer
Correct Answer: C
Chapter: 19
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
Correct Answer: B
Chapter: 19
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
Correct Answer: C
Chapter: 19
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
Correct Answer: B
Chapter: 19
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)
Correct Answer: A
Chapter: 19
Q292:
When overloading the >> operator for a class, the function should return a reference to ______.
A. ostream
B. istream
C. ofstream
D. ifstream
Correct Answer: B
Chapter: 19
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
Correct Answer: A
Chapter: 19
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
Correct Answer: C
Chapter: 19
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
Correct Answer: B
Chapter: 19
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
Correct Answer: A
Chapter: 19
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)
Correct Answer: A
Chapter: 19
Q298:
The comparison operator == is typically overloaded as a ______ function.
A. non-member
B. member
C. static
D. inline
Correct Answer: B
Chapter: 19
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
Correct Answer: D
Chapter: 19
Q300:
In C++, which operator is overloaded to allow cascading operations?
A. +
B. *
C. <<
D. >>
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now