What is polymorphism?
Posted by Syed Shakeer Hussiain P
category on 2/8/2009
for Beginner level | Views : 31752
If you found plagiarised (copied)
or inappropriate content,
please let us know
the original source along with your correct email id (to communicate) for further action.
Rating: 4.67 out of 5
Generally, it is the ability to appear in different forms. In oops concept, it is the ability to process objects differently depending on their data types. Its the ability to redefine methods for derived classes.
There Are Two Types of Polymorphism
- Static Polymorphism
- Dynamic Polymorphism
1. Static Polymorphism
In Static Polymorphism ,Which method is to be called is decided at compile-time only. Method Overloading is an example of Static Polymorphism.
Method overloading is a concept where we use the same method name many times in the same class,but different parameters. Depending on the parameters we pass, it is decided at compile-time only, which method is to calles. The same method name with the same parameters is an error and it is a case of duplication of methods which c# does not permits. In Static Polymorphism decision is taken at compile time.
public Class StaticPolyDemo
public void display(int x)
Console.WriteLine(“Area of a Square:”+x*x);
public void display(int x, int y)
Console.WriteLine(“Area of a Square:”+x*y);
public static void main(String args)
StaticPolyDemo spd=new StaticPolyDemo();
2. Dyanamic Polymorphism
In this Mechanism by which a call to an overridden function is resolved at a Run-Time( not at Compile-time). If a BaseClass contains method must be a Virtual method in C# to be overridden..
Public virtual void show()
Console.WriteLine(“From base class show method”);
Public Class DynamicPolyDemo : Test
Public override void show()
Console.WriteLine(“From Derived Class show method”);
Public static void main(String args)
DynamicPolyDemo dpd=new DynamicPolyDemo();
About the Author