Quiz on Overloading and Overriding in C++
By overloading, different methods or operators can have the same name, but with different signatures, each differing by either the number of input parameters or the type of input parameters, or both. Specifically, subclasses or child classes can override a method that is already implemented by one of their superclasses or parent classes. Now let’s take a quick quiz to understand overloading and overriding in C++ in detail.
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) What is the right way to describe operator overloading in C++? Which of the following operators cannot be overloaded? What is the output of the following code snippet? If a binary operator is being overloaded by using the member function, how many arguments must be provided? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code snippet? }; What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following program? What is the output of the following program? What is the output of the following program? Overriding the functions consists of the following: Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
#include <iostream>
using namespace std;
class Division
{
int num, num1;
public:
Division(int a, int b) { num = a; num1 = b; }
operator double() const {
return double(num) / double(num1);
}
};
int main() {
Division d(10, 15);
double val = d;
cout << val;
return 0;
} 4. Question
5. Question
#include <iostream>
using namespace std;
class QuizOrbit {
private:
int quizes;
public:
QuizOrbit() {
quizes = 0;
}
QuizOrbit(int q) {
quizes = q;
}
friend ostream &operator<<( ostream &output, const QuizOrbit &O ) {
output<< O.quizes;
return output;
}
};
int main() {
QuizOrbit Q1(11), Q2(5);
cout << “No. of Questions in Quiz1 are : ” << Q1 << endl;
cout << “No. of Questions in Quiz2 are : ” << Q2 << endl;
return 0;
} 6. Question
#include <iostream>
#include <string>
using namespace std;
class Student
{
static int rollno;
public:
void show()
{
rollno++;
cout<<rollno<<endl;
}
};
int Student::rollno = 15;
int main()
{
Student stu;
stu.show();
return 0;
} 7. Question
#include <iostream>
#include <string>
using namespace std;
class Student
{
string name;
public:
void concatenate(string name, string surname)
{
cout<<name+surname<<endl;
}
int main()
{
Student stu;
stu.concatenate(“annu”,”mehla”);
return 0;
} 8. Question
#include<iostream>
using namespace std;
class Parent1
{
int a;
public:
Parent1(int aa = 0) : a(aa) {}
void show() { cout << a << endl; }
};
class Parent2
{
int b;
public:
Parent2(int bb) :b(bb) {}
operator Parent1() const { return Parent1(b); }
};
void display(Parent1 p)
{
p.show();
}
int main()
{
Parent2 p(1010);
display(p);
display(20);
return 0;
} 9. Question
#include<iostream>
using namespace std;
int Addition(int x , int y = 20, int z=10)
{ return (x + y + z); }
int main()
{
cout << Addition(10);
return 0;
} 10. Question
#include <iostream>
using namespace std;
int Multiplication(int=0, int = 2);
int main()
{
cout << Multiplication(5);
return 0;
}
int Multiplication(int x, int y) { return (x*y); } 11. Question
#include <iostream>
using namespace std;
class Parent {
public:
void display() {
cout << “Parent Function” << endl;
}
};
class Child: public Parent {
public:
void display() {
cout << “QuizOrbit” << endl;
}
};
int main() {
Child c1;
c1.display();
return 0;
} 12. Question
#include <iostream>
using namespace std;
class Parent {
public:
void display() {
cout << “Parent Function” << endl;
}
};
class Child: public Parent {
public:
void display() {
cout << “Child Function” << endl;
}
};
int main() {
Child c1;
c1.Parent::display();
return 0;
} 13. Question
#include <iostream>
using namespace std;
class Parent {
public:
void display() {
cout << “Parent Function” << endl;
}
};
class Child: public Parent {
public:
void display() {
cout << “Child Function” << endl;
Parent::display();
}
};
int main() {
Child c1;
c1.display();
return 0;
} 14. Question
#include <iostream>
using namespace std;
class Parent {
public:
void display() {
cout << “Parent Function” << endl;
}
};
class Child: public Parent {
public:
void display() {
cout << “Child Function” << endl;
Parent::display();
}
};
int main() {
Child c1;
Parent* ptr = &c1;
ptr->display();
return 0;
} 15. Question
Summary
After taking the quiz, I hope you understand the concept of overloading and overriding in c++ in more detail.