Polymorphism MCQs Viva Questions
What is Polymorphism?
(A). Polymorphism means more than one function with the same tasks
(B). Polymorphism means more than one function with different tasks
(C). Polymorphism means functions with the same tasks
(D). Polymorphism means many functions in the main function with different names
Example of option (B). Polymorphism means more than one function with different tasks (Function overloading)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> using namespace std; void Sum_T4Tutorials(int a, int b) { cout << "sum = " << (a + b); } void Sum_T4Tutorials(double a, double b) { cout << endl << "sum = " << (a + b); } // Driver code int main() { Sum_T4Tutorials(4, 6); Sum_T4Tutorials(8.1, 7.4); return 0; } |
What is Operator overloading?
(A). defining additional tasks to operators without changing their actual meaning
(B). defining additional tasks to operators by changing their actual meaning
(C). to discourage the operator to work according to its actual meaning
(D). None of these
Example of the option (A). defining additional tasks to operators without changing their actual meaning
A new definition to base class function in the derived class with the same signatures is called ______?
(A). Function overloading
(B). Function overriding
(C). Friend Function
(D). None of these
Example of option (B). Function overriding
Which is the example of compile time Polymorphism?
(A). Function Overloading
(B). Operator Overloading
(C). A and B
(D). Function overriding
Which is the example of run time Polymorphism?
(A). Function Overloading
(B). Operator Overloading
(C). Function overriding
(D). B and C
How more than one function can be implemented in Polymorphism?
(A). two functions in the same class
(B). two functions in the different class
(C). one function in parent and one in child class
(D). All of these
Example of the option (A). two functions in the same class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> using namespace std; class T4Tutorials { public: int sum(int X,int Y) // Function with parameter { return X+Y; // this function is performing sumition of two Integer value } int sum() { // Function with same name but without parameter string first= "Welcome to"; string second="T4Tutorials.com"; // in this function concatenation is performed string Concated= first+second; cout<<Concated<<endl; } }; int main(void) { T4Tutorials object; // Object is created cout<<object.sum(7, 3)<<endl; //first method is called object.sum(); // second method is called return 0; } |
Example of option (B). two functions in a different class, (C). tone function in parent and one in child class
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 |
#include <iostream> using namespace std; // Base class class Zoo_Animals { public: void Zoo_AnimalsSound() { cout << "The Zoo_Animals makes a sound "<<endl; ; } }; // Derived class class cat : public Zoo_Animals { public: void Zoo_AnimalsSound() { cout << "The cat: meows "<<endl; ; } }; // Derived class class peacock : public Zoo_Animals { public: void Zoo_AnimalsSound() { cout << "The peacock: scream "<<endl; ; } }; int main() { Zoo_Animals myZoo_Animals; cat mycat; peacock mypeacock; myZoo_Animals.Zoo_AnimalsSound(); mycat.Zoo_AnimalsSound(); mypeacock.Zoo_AnimalsSound(); return 0; } |
Which of the following can have Polymorphism?
(A). Only functions
(B). only operators
(C). both functions and operators
(D). None of these
Example of the option (A). Functions Polymorphism
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> using namespace std; class T4Tutorials { public: int sum(int X,int Y) // Function with parameter { return X+Y; // this function is performing sumition of two Integer value } int sum() { // Function with same name but without parameter string first= "Welcome to"; string second="T4Tutorials.com"; // in this function concatenation is performed string Concated= first+second; cout<<Concated<<endl; } }; int main(void) { T4Tutorials object; // Object is created cout<<object.sum(7, 3)<<endl; //first method is called object.sum(); // second method is called return 0; } |
Example of option (B). operators Polymorphism
Important table for viva questions & MCQs
Early binding | late binging |
Order of Execution: 1st(Early binding) then 2nd (late binging) | |
static binging | Dynamic Binding |
Compile-time | Run time polymorphism |
Matching of a function call with function definition is performed at compiler time. | Matching of a function call with function definition is performed at run time. |
Full information about function calling and matching with function definition is visible to the compiler during compile time | Full information about function calling and matching with function definition is not visible to the compiler during compile time but it’s visible during run time. |
More efficient: because the compiler already has knowledge that what code will execute | More flexible:
|
Fast execution | Slow execution |
Examples: Function overloading and operator overloading | Examples: Virtual functions |
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