Pages

Men

rh

7/01/2012

Static Polymorphism in C#

Static or Compile time Polymorphism:
  • The method is to be called is decided at compile-time only. Method overloading is an example of this.
  • 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.
  •  The same method name with the same parameters is an error and it is a case of duplication of    methods  which C# does not permit.
  •  In Static Polymorphism the decision is made at compile time.
    
Example:
public Class StaticDemo
{
    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[])
  {
    StaticDemo spd=new StaticDemo();
    Spd.display(5);
    Spd.display(10,3);
  }
}

No comments :

Post a Comment