CARVIEW |
Operator Overloading
Question 1
- By overloading new operator
- By making an empty private new operator.
- By making an empty private new and new[] operators
- By overloading new operator and new[] operators
Question 2
1) Comparison Operator ( == ) 2) Assignment Operator ( = )
- Both 1 and 2
- Only 1
- Only 2
- None of the two
Question 3
- Postfix ++
- Comparison Operator
- Insertion Operator <<
- Prefix++
Question 4
Which of the following is an example of compile-time polymorphism?
Function Overriding
Virtual function
Function Overloading
Dynamic Casting
Question 5
#include<iostream>
using namespace std;
class Point {
private:
int x, y;
public:
Point() : x(0), y(0) { }
Point& operator()(int dx, int dy);
void show() {cout << "x = " << x << ", y = " << y; }
};
Point& Point::operator()(int dx, int dy)
{
x = dx;
y = dy;
return *this;
}
int main()
{
Point pt;
pt(3, 2);
pt.show();
return 0;
}
- x = 3, y = 2
- Compiler Error
- x = 2, y = 3
Question 6
#include <iostream>
using namespace std;
class Test2
{
int y;
};
class Test
{
int x;
Test2 t2;
public:
operator Test2 () { return t2; }
operator int () { return x; }
};
void fun ( int x) { cout << "fun(int) called"; }
void fun ( Test2 t ) { cout << "fun(Test 2) called"; }
int main()
{
Test t;
fun(t);
return 0;
}
- fun(int) called
- fun(Test 2) called
- Compiler Error: Ambiguous call to fun()
Question 7
Which of the following operators cannot be overloaded?
- . (Member Access or Dot operator)
- ?: (Ternary or Conditional Operator )
- :: (Scope Resolution Operator)
- .* (Pointer-to-member Operator )
- All of the above
Question 8
Which of the following statements are true regarding C++?
(a) Overloading gives the capability to an existing operator to operate on other data types.
(b) Inheritance in object oriented programming provides support to reusability.
(c) When object of a derived class is defined, first the constructor of derived class is executed then constructor of a base class is executed.
(d) Overloading is a type of polymorphism.
Choose the correct option from those given below:
(a) and (b) only
(a), (b) and (c) only
(a), (b) and (d) only
(b), (c) and (d) only
Question 9
What is Operator overloading?
When an operator is overloaded, it takes on an additional meaning relative to a certain class.
There are 9 questions to complete.