Chapter 15: Polymorphism - Online Test

Q1. Which of the following operator is by default overloaded by the compiler?
Answer : Option D
Explaination / Solution:
No Explaination.


Q2.

Based on the following program answer the question

#include

using namespace std;

class Point {

private:

int x, y;

public:

Point(int x1,int y1)

{

x=x1;y=y1;

}

void operator+(Point &pt3);

void show() {cout << "x = " << x << ", y = " << y; } };

void Point::operator+(Point &pt3)

{

x += pt3.x;

y += pt3.y;

}

int main()

{

Point pt1(3,2),pt2(5,4);

pt1+pt2;

pt1.show();

return 0;

}

Which of the following operator is overloaded?

Answer : Option A
Explaination / Solution:
No Explaination.


Q3.

Based on the following program answer the question

#include<iostream>

using namespace std;

class Point {

private:

int x, y;

public:

Point(int x1,int y1)

{

x=x1;y=y1;

}

void operator+(Point &pt3);

void show() {cout << "x = " << x << ", y = " << y; } };

void Point::operator+(Point &pt3)

{

x += pt3.x;

y += pt3.y;

}

int main()

{

Point pt1(3,2),pt2(5,4);

pt1+pt2;

pt1.show();

return 0;

}

Which of the following statement invoke operator overloading?
Answer : Option A
Explaination / Solution:
No Explaination.


Q4.

Based on the following program answer the question

#include<iostream>

using namespace std;

class Point {

private:

int x, y;

public:

Point(int x1,int y1)

{

x=x1;y=y1;

}

void operator+(Point &pt3);

void show() {cout << "x = " << x << ", y = " << y; } };

void Point::operator+(Point &pt3)

{

x += pt3.x;

y += pt3.y;

}

int main()

{

Point pt1(3,2),pt2(5,4);

pt1+pt2;

pt1.show();

return 0;

}

What is the output for the above program?
Answer : Option A
Explaination / Solution:
No Explaination.