What is Polymorphism?

Posted by in OOPS category on for Beginner level | Views : 72518 red flag
Rating: 3 out of 5  
 1 vote(s)

This article will discuss about Polymorphism in object oriented programming.

 Download source code for What is Polymorphism?


This article will discuss about Polymorphism in object oriented programming. Watch our 500 videos on Azure, WCF, WPF, LINQ, Design Patterns, WWF, Silverlight, UML @ http://www.questpond.com/

What is Polymorphism?

  • Polymorphism is one of the primary characteristics (concept) of object-oriented programming.
  • Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details.
  • Polymorphism is the characteristic of being able to assign a different meaning specifically, to allow an entity such as a variable, a function, or an object to have more than one form.
  • Polymorphism is the ability to process objects differently depending on their data types.
  • Polymorphism is the ability to redefine methods for derived classes.

Types of Polymorphism

  • Compile time Polymorphism
  • Run time Polymorphism

Compile time Polymorphism

  • Compile time Polymorphism also known as method overloading
  • Method overloading means having two or more methods with the same name but with different signatures
Example of Compile time polymorphism


Run time Polymorphism

  • Run time Polymorphism also known as method overriding
  • Method overriding means having two or more methods with the same name , same signature but with different implementation
Example of Run time Polymorphism

You can find source code at the top of this article.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Gurunatha Dogi
Member Level: Starter
Member Status: Member
Member Since: 8/13/2009 12:50:13 AM
Country: India
Gurunatha Dogi
Gurunatha Dogi, is a software engineer by education and profession. He likes c#, java, php, , asp.net, sql server and seo optimization. During free time he likes to write blogs on various technical topics and tips and tricks on search engine optimization. He likes to play guitar and cricket. Currently he is working in @Questpond one well known of e-learning firm in India.

Login to vote for this post.

Comments or Responses

Posted by: Nav234 on: 7/16/2010
Hi guru,
that was a good example.
But after seeing your code and example,i have a small

In Over ridding example (Runtime Poly) ,
you have two class Prism and pyramid,with same method name GetVolume ();
then by using this main method,u called particular method from particular class,
Shapes objshapes = new Pyramid() ;
Then y v go for Overriding concept ?,or should i understand like same method name ,but fuction to a class name ur calling rite.or what is use u got here.

Can u explain ?,im a beginner

thanks in advance

Posted by: Brubond35 on: 6/5/2012 | Points: 25
HI I think, In Runtime polymorphism example their is small mistake,
I think he may forgot to use virtual keyword in the base class.
If we use the same code to create the classes and if we tried to
Circle objCircle = new Sphere() ;
then it will execute the Circle class function only not he derived class function.
So I think think their should be another example for Runtime polymorphism

Posted by: Rajesh081725 on: 11/26/2012 | Points: 25
Hi Guru,
Can u Give some example of code with overriding virutual function

Login to post response

Comment using Facebook(Author doesn't get notification)