Test your technical skills online, appear in Virtual Interview and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Make friends on DotNetFunda.com and expand your network!
Winners

Win Prizes

Announcements
Like us on Facebook
Sponsor
Top Articles Author
Sun, 20-Apr-2014 Authors
All Time Authors
Sourav.Kayal
39750
SheoNarayan
34800
Niladri.biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads

What is polymorphism?

Syedshakeer
Posted by under OOPS category on for Beginner level | Views : 30855 red flag
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
3 vote(s)


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

  1. Static Polymorphism
  2. 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();
    Spd.display(5);
   Spd.display(10,3);
 }
}

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..


Class Test
{
  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();
      Dpd.show();
       
    }
}





Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:




About the Author

Syedshakeer

Full Name: Syed Shakeer Hussiain P
Member Level:
Member Status: Member
Member Since: 2/5/2009 3:12:18 AM
Country: India
Syed Shakeer Hussain
http://www.dotnetfunda.com

Shakeer Hussain has completed his Master of Computer Applications degree from Deccan College of engg and technology of Osmania University.He is a MVM of www.dotnetspider.com.He has good experience in the areas of ASP.NET, C#.NET, VB.NET, SQL SERVER 2000/2005 and Windows Mobile. He has worked in Windows Mobile,Web Applicatin and ERP projects.
Login to vote for this post.

Comments or Responses

Posted by: WebMaster on: 9/6/2009

For more details on this subject, kindly visit

http://forums.asp.net/p/1460715/3356138.aspx

Regards,
Webmaster


Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.

Comment using Facebook