0% found this document useful (0 votes)
2 views2 pages

Introduction To Polymorphism

The document introduces polymorphism in object-oriented programming (OOP), explaining its definition, purpose, and types in C++. It details compile-time (static) and runtime (dynamic) polymorphism with examples of function overloading. Additionally, it includes an interactive activity and a homework assignment related to operator overloading and function overloading.

Uploaded by

amirjawad027
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Introduction To Polymorphism

The document introduces polymorphism in object-oriented programming (OOP), explaining its definition, purpose, and types in C++. It details compile-time (static) and runtime (dynamic) polymorphism with examples of function overloading. Additionally, it includes an interactive activity and a homework assignment related to operator overloading and function overloading.

Uploaded by

amirjawad027
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

cswithalam mehtabalam1

Introduction to Polymorphism

1. What is Polymorphism?
Polymorphism in OOP allows objects of different types to be treated as objects of a common base
type. It enables flexibility and reusability in code.

● Literal Meaning: “Many forms.”


● Purpose: Perform a single action in different ways.

2. Types of Polymorphism in C++

1. Compile-time (Static Polymorphism):


○ Achieved through function overloading and operator overloading.
2. Runtime (Dynamic Polymorphism):
○ Achieved through inheritance and virtual functions.

3. Syntax and Example: Function Overloading (Compile-time Polymorphism)

#include <iostream>

using namespace std;

class Calculator {

public:

int add(int a, int b) {

return a + b;

double add(double a, double b) {

return a + b;

};

Visit my website: https://mehtab.netlify.app/


cswithalam mehtabalam1

int main() {

Calculator calc;

cout << "Integer Addition: " << calc.add(5, 3) << endl;

cout << "Double Addition: " << calc.add(2.5, 3.8) << endl;

return 0;

4. Interactive Activity:
Write a program to demonstrate operator overloading for the + operator.

5. Homework Assignment:
Write a program that demonstrates both function overloading and operator overloading.

Visit my website: https://mehtab.netlify.app/

You might also like