Roll No# 4823
Polymorphism
• Polymorphism is a feature of OOP with
single interface and multiple methods.
• It also means “One name and ...
Polymorphism
• It indicates calling one or more functions using
same name.
• It is achieved using overloading of functions...
• Multiple methods imply two or more
functions with the same name but with
different signatures.
• For example, we have tw...
• With respect to previous example,
whether we find sum of two integers or two
floating point values it doesn’t matter for...
How can we access the member of class?
• The member of a class can be access
through pointer to the class.
• General synta...
Types of Polymorphism
• Also called as static
binding, it binds an object to
a function call during
compilation time.
• Re...
Polymorphism
Polymorphism
Polymorphism
Polymorphism
Upcoming SlideShare
Loading in …5
×

Polymorphism

1,277 views

Published on

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,277
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
92
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Polymorphism

  1. 1. Roll No# 4823
  2. 2. Polymorphism • Polymorphism is a feature of OOP with single interface and multiple methods. • It also means “One name and multiple forms”. • After the inheritance it is another most important feature of OOP. • It helps us to reduce complexity using a single interface and multiple methods.
  3. 3. Polymorphism • It indicates calling one or more functions using same name. • It is achieved using overloading of functions and overloading of operators. • Polymorphism is achieved using overloading of functions using:  Multiple methods  Single interface
  4. 4. • Multiple methods imply two or more functions with the same name but with different signatures. • For example, we have two overloaded add functions as shown below: // adds two integer values add(int a, int b) { int c =a+b; cout<<c<<endl; } // adds two floating values add(float a, float b) { float c =a+b; cout<<c<<endl; } The above two functions are called methods
  5. 5. • With respect to previous example, whether we find sum of two integers or two floating point values it doesn’t matter for us. • What is required is “to add two values” • So, it is logical to use add as the function name. We may call two functions as shown below: add(10,20); //Invoke the first function add(1.5,3.5); //Invoke the second add function
  6. 6. How can we access the member of class? • The member of a class can be access through pointer to the class. • General syntax; P -> member class; • P is pointer to object. • -> is member access operator. • Member class. It is the member of the object;
  7. 7. Types of Polymorphism • Also called as static binding, it binds an object to a function call during compilation time. • Refers to events that occur during compile time. • Execution is much faster. • Not flexible since functions are decided during compilation time. • Achieved using normal function calls, function overloading and operator overloading. • Also called as dynamic binding, it binds an object to a function call during run time. • Refers to events that occur during run time. • Execution is slower. • Very flexible since executable functions are decided during run time. • Achieved using inheritance and virtual functions.

×