What is Polymorphism?Polymorphism means one thing having many (poly) forms. Suppose the example shown in the following diagram:
Compile Time Polymorphism
- Method overloading
- Operator overloading
- By changing the number of parameters used.
- By changing the order of parameters.
- By using different data types for the parameters.
Run Time Polymorphism
- Method overriding is only possible in a derived class, not within the same class where the method is declared.
- Only those methods overridden in the derived class declared in the base class using the virtual keyword or abstract keyword.
In the preceding program we declare the Virtual method that returns 10 and the same method we are using in the class Amount using the override keyword that at runtime returns 500 without changing the values of the method, even the names are the same, so the example above shows runtime polymorphism. In my next article, we will see in detail a program with runtime polymorphism.