Pointers and Polymorphism in C++: Introduction of Polymorphism and Types

Pointers and Polymorphism in C++: Introduction of Polymorphism and Types
Slide Note
Embed
Share

Polymorphism in C++ involves combining different forms under the same name to create multiple functions with various purposes. This concept allows for reusing code, utilizing single variable names for multiple data types, and exhibiting different behaviors in different situations. Types of polymorphism include compile-time (static) polymorphism, which involves function overloading and operator overloading, and runtime (dynamic) polymorphism, which uses virtual functions to implement late binding.

  • C++
  • Polymorphism
  • Compile-time
  • Runtime
  • Virtual functions

Uploaded on Apr 13, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Pointers And Polymorphism In C++ Introduction Of Polymorphism, Types Of Polymorphism POLYMORPHISM TYPES OF POLYMORPHISM

  2. What Is Polymorphism? Polymorphism Is The Combination Of Two Greek Words, Poly Means : Many Morphism Means :Forms Its stands for same name multiple forms . It means more than one function with same name ,with different working. We can define multiple things, with same name in a program for different purpose. EXAMPLE int main() { triangle t; rectangle r; t.draw (a, b, c); r.draw (e, f); } Function draw() shows the property of Polymorphism it will behave differently with object t and object r .

  3. Real Life Example Of Polymorphism So The Same Person Posses Different Behavior In Different Situations. This Is Called Polymorphism. Advantages: It helps programmers reuse the code and classes once written. Single variable name can be used to store variables of multiple data types. 1. 2.

  4. TYPES OF POLYMORPHISM

  5. 1.COMPILE TIME OR STATIC POLYMORPHISM(STATIC) Those Operations That Take Place During The Compile Time Are Called Static Or Compile Time Polymorphism. 1. Function Overloading: When There Are Multiple Functions With Same Name But Different Parameters Then These Functions Are Said To Be Overloaded. Functions Can Be Overloaded By Change In Number Of Arguments Or/And Change In Type Of Arguments. 2. Operator Overloading: C++ Also Provide Option To Overload Operators. For Example, We Can Make The Operator ( + ) For String Class To Concatenate Two Strings. We Know That This Is The Addition Operator Whose Task Is To Add Two Operands. So A Single Operator + When Placed Between Integer Operands , Adds Them And When Placed Between String Operands, Concatenates Them.

  6. 2. RUN TIME POLYMORPHISM (DYNAMIC)) : Runtime Polymorphism Is Also Known As Dynamic Polymorphism Or Late Binding. In Runtime Polymorphism, The Function Call Is Resolved At Run Time. 2.1 Virtual Functions: A Virtual Function IsAnother Way Of Implementing Run-time Polymorphism In C++. It Is A Special Function Defined In A Base Class And Redefined In The Derived Class. To Declare A Virtual Function, You Should Use The Virtual Keyword. The Keyword Should Precede The Declaration Of The Function In The Base Class. keyword ex: ->

  7. Difference Between Static And Dynamic Polymorphism STATIC POLYMORPHISM DYNAMIC POLYMORPHISM 1. A type of polymorphism that collect the informationto call a method during compile time. 1. A type of polymorphism that collects the information to call a method during run time. 2. Occurs at compile time. 2. Occurs at run time. 3. Known as static binding and early binding. 3. Known as dynamic binding and late binding. 4. Execution speed is high. 4. Execution speed is low. 5. Method overloading is an example of static binding. 5. Method overriding is an example of dynamic binding.

  8. THANK YOU

More Related Content