What is Polymorphism?
Polymorphism means same operation may behave differently on different classes.
- Example of Compile Time Polymorphism:
- Example of Run Time Polymorphism:
Example of Compile Time Polymorphism
- Method Overloading: Method with
same name but with different arguments is called method overloading.
- Method Overloading forms compile-time
Example of Method Overloading:
Example of Run Time Polymorphism
- Method Overriding: Method
overriding occurs when child class declares a method that has the same type
arguments as a method declared by one of its superclass.
- Method overriding forms Run-time
Note: By default functions are not virtual in C# and so you need to write
“virtual” explicitly. While by default in Java each function are virtual.
Example of Method Overriding:
virtual void hello()
Class child :
override void hello()
static void main()
parent objParent =
R A Patel