Class 12 Computer Science Important Questions (ASSEB / AHSEC)

Chapter 2 - Polymorphism and Function Overloading

1. What is Polymorphism?

Answer : In C++, polymorphism is a feature that allows the same function name or same operator to behave differently in different situations.

2. What are the types of Polymorphism?

Answer :There are mainly two types of polymorphism

  • Compile-time Polymorphism – achieved at compile time
  • Run-time Polymorphism – achieved at runtime.

3. What is Compile-time polymorphism?

Answer : In compile time polymorphism, the compiler decides which function to call based on the number, type or order of the arguments.It is achieved through:

  • Function Overloading
  • Operator Overloading

4. What is runtime polymorphism?

Answer:Run-time Polymorphism is achieved at runtime. It is also called Late Binding. It is achieved though :

  • Function Overiding
  • Virtual Functions

5. What is Function Overloading?

Answer : Function Overloading is a feature of C++ that allows us to create multiple functions with the same name but different parameter lists.The functions may differ in the following ways:

  • No of parameters
  • Type of parameters
  • Order of parameters

6. What is Operator Overloading

Answer : Operator overloading is a feature that allows standard operators (like +, -, *, ==) to behave differently based on the data types they interact with.

7. What is polymorphism? Give an example illustrating its use in a c++ program.

Answer : In C++, polymorphism is a feature that allows the same function name or same operator to behave differently in different situations.

This program illustrates polymorphism using function overloading.

#include <iostream>
using namespace std;

int sum (int a, int b) {
    return a + b;
}
float sum(float a, float b) {
    return a + b;
}
int sum(int a, int b, int c) {
    return a + b + c;
}

int main() {
cout << sum(2, 3) << endl;                       // calls int version
cout << sum(2.5, 3.5) << endl;                   // calls float version
cout << sum(1, 2, 3);                                   // calls 3-parameter version
}

Scroll to Top