Comparison between runtime polymorphism and compile time polymorphism -
Certainly! Here's a short description of the comparison between runtime polymorphism and compile-time polymorphism in a PowerPoint presentation (PPT):
Slide 1: Title
Title: "Comparison: Runtime Polymorphism vs. Compile-Time Polymorphism"
Slide 2: Introduction
Introduction to polymorphism.
Mention that polymorphism is a fundamental concept in object-oriented programming.
Slide 3: Compile-Time Polymorphism
Define Compile-Time Polymorphism.
Highlight that it's also known as Static or Early Binding Polymorphism.
Explain that it's resolved during compile-time.
Provide examples like function overloading.
Slide 4: Runtime Polymorphism
Define Runtime Polymorphism.
Highlight that it's also known as Dynamic or Late Binding Polymorphism.
Explain that it's resolved during runtime.
Provide examples like method overriding.
Slide 5: Key Differences
List the key differences between compile-time and runtime polymorphism.
Differences might include resolution time, method signatures, and performance implications.
Slide 6: Use Cases
Explain when to use compile-time polymorphism.
Provide scenarios where it's beneficial.
Slide 7: Use Cases (Cont.)
Explain when to use runtime polymorphism.
Provide scenarios where it's beneficial.
Slide 8: Pros and Cons
List the advantages and disadvantages of compile-time polymorphism.
List the advantages and disadvantages of runtime polymorphism.
Slide 9: Performance Comparison
Compare the performance aspects of both types of polymorphism.
Discuss factors like execution speed and memory usage.
Slide 10: Conclusion
Summarize the main points.
Suggest when to use each type of polymorphism based on the application's requirements
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Comparison between runtime polymorphism and compile time polymorphism
1. Course Name: Object Oriented Programming & Data Structures
Course In-charge: : Prof. VIVEK D. DESHMUKH
Course Seminar on
“Comparison between runtime polymorphism and compile time
polymorphism”
Presented by
CHAITALI UKE
2. What is Polymorphism
Polymorphism :-
Poly means ‘Many’
Morphism means ‘ Forms’
The word polymorphism means having many forms. In simple words, we
can define polymorphism as the ability of a message to be displayed in
more than one form
4. For Example
+ Operator is used for Addition of two integer
For Example:
10 + 20 = 30
It is also used for joining Two Strings.
For Example:
“key” + “board” = keyboard
5. Type of Polymorphism
In C++ polymorphism is mainly divided into two types:
1] Compile time Polymorphism
2] Runtime Polymorphism
7. Compile time polymorphism
This type of polymorphism is achieved by function overloading or operator
overloading
Function Overloading: When there are multiple functions with same name but
different parameters then these functions are said to be overloaded.
.
8. Operator Overloading:
C++ allows you to specify more than one definition for an operator in the same
scope, which is called operator overloading.
You can redefine or overload most of the built-in operators available in C++.
Operator that are not overloaded are follows –
• scope operator (::)
• sizeof
• Member selector (.)
• Member pointer selector (*)
• Ternary operator (?)
9. This type of polymorphism is achieved by Function Overriding.
Virtual Function is a member function which is declared within base class
and is re-defined (overridden) by derived class.
Function overriding on the other hand occurs when a derived class has a
definition for one of the member functions of the base class. That base
function is said to be overridden.
Runtime polymorphism
10. // C++ program for function overloading
#include<iostream>
using namespace std;
class program
{
public:
void func(int x)
{
cout << "value of x is " <<
x << endl;
}
void func(double x)
{
cout << "value of x is " <<
x << endl;
}
}
void func(int x, int y)
{
cout << "value of x and y
is " << x << ", " << y << endl;
}
};
int main() {
program obj1;
obj1.func(7);
obj1.func(9.132);
obj1.func(85,64);
return 0;
}
Output:
value of x is 7
value of x is 9.132
value of x and y is 85, 64
11. //Runtime Polymorphism using Virtual Function:
#include<iostream>
using namespace std;
class Base{
public:
virtual void print(){
cout<<"n
Called Print function in Base Classn";
}
void show(){
cout<<"n
Called Show function in Base Classn";
}
};
class Derived : public Base{
public:
void print(){
cout<<"n
Called Print function in Derived Classn";
}
void show(){
cout<<"n
Called Show function in Derived Classn";
}
};
int main(){
Base *bptr;
Derived D1;
bptr = &D1;
bptr->print();
bptr->show();
return 0;
}
Output
Called Print function in Derived Class
Called Show function in Base Class
12. The following table demonstrates the difference between runtime polymorphism
and compile-time polymorphism:
Sr.
No
Compile Time Polymorphism Run time Polymorphism
1
In Compile time Polymorphism, the call is
resolved by the compiler.
In Run time Polymorphism, the call is not resolved
by the compiler.
2
It is also known as Static binding, Early
binding and overloading as well.
It is also known as Dynamic binding, Late binding
and overriding as well.
3
Method overloading is the compile-time
polymorphism where more than one
methods share the same name with different
parameters or signature and different return
type.
Method overriding is the runtime polymorphism
having same method with same parameters or
signature, but associated in different classes.
4
It is achieved by function overloading and
operator overloading.
It is achieved by virtual functions and pointers.
5
It provides fast execution because the method
that needs to be executed is known early at
the compile time.
It provides slow execution as compare to early
binding because the method that needs to be
executed is known at the runtime.