Constructors MCQS
Constructors MCQS
**Answer:** c
a) `+`, `-`
c) `<<`, `>>`
d) `++`, `--`
**Answer:** b
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction
**Answer:** a
a) `operator`
b) `overload`
c) `function`
d) `define`
**Answer:** a
---
b) `void operator+()`
d) `Complex +operator()`
**Answer:** a
6. **Which of the following is the correct way to overload the `<<` operator
for output?**
**Answer:** a
**Answer:** c
8. **What is the return type of the postfix `++` operator overload function?
**
a) `void`
b) `ClassName&`
d) `int`
**Answer:** c
---
a) `ClassName operator-()`
c) `void operator-()`
d) `int operator-()`
**Answer:** a
10. **Which function overloads the `==` operator for comparing two
objects?**
c) `ClassName operator==()`
d) `int operator==(ClassName obj)`
**Answer:** a
d) `float operator[]()`
**Answer:** a
**Answer:** a
---
b) To improve performance
**Answer:** a
14. **Which operator must be overloaded as a friend function?**
a) `+`
b) `=`
d) `[]`
**Answer:** c
a) No
c) Only in Java
**Answer:** b
16. **What is the correct syntax for overloading the `()` operator?**
a) `void operator()(args)`
b) `ClassName operator()(args)`
c) `int operator()()`
**Answer:** a
---
17. **What happens if the `=` operator is not overloaded for a class?**
a) Compiler generates a default assignment operator
b) Program crashes
**Answer:** a
a) `+`
b) `=`
c) `<<`
d) `==`
**Answer:** b
```cpp
class Test {
public:
int x;
Test operator+(Test t) {
Test temp;
temp.x = x + t.x;
return temp;
};
int main() {
t1.x = 5;
t2.x = 10;
Test t3 = t1 + t2;
```
a) `5`
b) `10`
c) `15`
d) Error
**Answer:** c
a) `*` (dereference)
b) `+`
c) `=`
d) `>>`
**Answer:** a