Operator overloading Solved MCQ’s (OOP)
Let us see the important Operator overloading Solved MCQ’s. Operator overloading is a very important topic of object-oriented programming (OOP). 1. we can define a binary operator as : A. The operator that performs its action on two operand B. The operator that performs its action on three operand C. The operator that performs its action on any number of operands D. The operator that performs its action on a single operand 2. ______ is not an operator overloaded by the C++ language. A. <<. B. +. C. pow D. >>. 3. correct example of a binary operator is _______. A. — B. + C. ++ D. Dereferencing operator(*) 4. true about streams is ______. a. a sequence of bytes b. an ordered sequence c. bytes can go through the stream simultaneously d. Bytes will go out at last that enters first into the stream A. A only B. A and B C. C only D. A and D 5. ____ is a correct example of a unary operator. A. / B. — C. & D. == 6. when we use an operator on user-defined class objects, operator overloading: A. always be used must B. never be used must C. with three exceptions must never be used D. with three exceptions must always be used 7. Ternary operator is shown as _____. A. === B. && C. ?: D. ||| 8. Overloading the addition (+) operator is correct function name OF : A. operator(+). B. operator_+. C. operator+. D. operator:+. 9. Choose the output of the following C++ code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> #include <string> using namespace std; class complex { int i; int j; public: complex(int a, int b) { i = a; j = b; } complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; } void show(){ cout<<"Please note it that Complex Number is: "<<i<<" + i"<<j<<endl; } }; int main(int argc, char const *argv[]) { complex c1(1,2); complex c2(3,4); complex c3 = c1 + c2; c3.show(); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <iostream> #include <string> using namespace std; class com { int i; int j; public: complex(){} com(int a, int b) { i = a; j = b; } com operator+(complex c) { comPlex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; } void show(){ cout<<"Please note it that Complex Number is: "<<i<<" + i"<<j<<endl; } }; int main(int argc, char const *argv[]) { com c1(1,2); com c2(3,4); com c3 = c1 + c2; c3.show(); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include <iostream> #include <string> using namespace std; class compl { int i; int j; public: compl(){} compl(int a, int b) { i = a; j = b; } compl operator+(compl c) { compl temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; } void operator+(compl c) { compl temp; temp.i = this->i + c.i; temp.j = this->j + c.j; temp.show_poss(); } void show(){ cout<<"Complex Number: "<<i<<" + i"<<j<<endl; } void show_poss(){ cout<<"The result after addition will be looks like: "<<i<<" + i"<<j<<endl; } }; int main(int argc, char const *argv[]) { compl c1(1,2); compl c2(3,4); c1 + c2; return 0; } |
OOP MCQs
- OOP intro & examples MCQs
- Classes and Inheritance MCQs
- Friend Function MCQs
- Virtual Function MCQs
- Polymorphism MCQs
- Polymorphism MCQs 2
- Operator overloading MCQs
- Object Oriented Programming MCQs – Very Important
Programming C Plus Plus MCQs Homepage
- Low-level and high-level languages MCQs
- Procedural and non Procedural languages MCQs
- C++ STANDARD LIBRARY MCQs
- Array MCQs
- Arrays MCQs 2
- Pointers Solved MCQs
- Inline Function MCQs – C++
- Top 50 Programming C++ MCQs
- MCQs of introduction to programming
- Past Papers 2022 C++ MCQs
- Past Papers 2021 C++ MCQs
- Past Papers 2020 C++ MCQs
- Past Papers 2019 C++ MCQs
- Highly Recommended C++ Important MCQs with Explanation
- OOP
- OOP intro & examples MCQs
- Classes and Inheritance MCQs
- Friend Function MCQs
- Virtual Function MCQs
- Polymorphism MCQs
- Polymorphism MCQs 2

