Dynamic Polymorphism in C#

Dynamic Polymorphism
The polymorphism in which compiler identifies which polymorphic form to execute at runtime but not at compile time is called run time polymorphism or late binding.
Advantage of late binding is flexibility and disadvantage is execution will be slow as compiler has to get the information about the method to execute at run time.  
  1. class Shape    
  2.  {    
  3.     public virtual void Draw()    
  4.     {    
  5.           Console.WriteLine("Shape");    
  6.     }    
  7.  }    
  9.  class Circle : Shape    
  10.  {    
  11.     public override void Draw()    
  12.     {    
  13.           Console.WriteLine("Shape");    
  14.     }    
  15.  }    
In this run time polymorphism or method overriding we can override a method in base class by creating similar method in derived class; this can be achieved by using “virtual & override” keywords.

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now