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.
- class Shape
- {
- public virtual void Draw()
- {
- Console.WriteLine("Shape");
- }
- }
-
- class Circle : Shape
- {
- public override void Draw()
- {
- Console.WriteLine("Shape");
- }
- }
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.