Search This Blog

Friday, July 12, 2019

Polymorphism

Polymorphism is often expressed as 'one interface, multiple functions'

Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.
Static polymorhism:Function Overoading,Operator Overloading


Run time polymorphism or method overriding means same method names with same signatures different class.


Function Overlading   One Function Name overloaded with multiple job is kown as Function Overloading

void f1(int z);  //generate error
int f1(int a)

return type does not matter same or different
void f1(int z);  //ok
int   f1(double a)


public   int  print()  tricks
        {
            return 1;
        }

       public  void print(int i, int k, string abc)
        {
            Console.WriteLine("Printing int: {0}", i);
        }
     
      public   void print(double f)
        {
            Console.WriteLine("Printing float: {0}", f);
        }
      public   void print(string s)
        {
            Console.WriteLine("Printing string: {0}", s);
        }

No comments :