What is the difference between compile time polymorphism and run time polymorphism
Vijay Kumar
- Compile time Polymorphism Compile time Polymorphism also known as method overloading. Method overloading means having two or more methods with the same name but with different signatures.- Run time Polymorphism Run time Polymorphism also known as method overriding. Method overriding means having two or more methods with the same name , same signature but with different implementation.
For compile time polymorphism, the method execution path / method binding happens at the compile time. For run time, it happens at run time, which it provides which method to be called will be decided at run time, eventually the method binding happens at run time. Early binding is implemented using Method over-loading, with same function name having different parameters. Late binding is implemented using method over-riding. Polymorphism is simply, One Interface having many forms. Means that we have a single method that performs / exhibits / behaves differently depending on the situation. Plz refer the Link : https://msdn.microsoft.com/en-us/library/ms173152.aspx
Compile time Polymorphism:- public class Class1 { public void NumbersAdd(int a, int b) { Console.WriteLine(a + b); } public void NumbersAdd(int a, int b, int c) { Console.WriteLine(a + b + c); } } Run time Polymorphism:- namespace polymorphism {public class Bclass{public virtual void simple(){Console.WriteLine("Hello Arjun");} }public class CClass :Bclass{public override void simple(){Console.WriteLine("Hi Sanju");}}class Program{static void Main(string[] args){CClass objC = new CClass();objC.simple();Bclass objb = new CClass();objb.simple();Console.ReadLine();}}}
http://www.aspdotnet-suresh.com/2013/09/compile-time-polymorphism-vs-run-time-polymorphism-in-csharp.html