Polymorphism is a concept in which a class containg more than one method with the same name but behaviour of each method is different is called polymorphism.
There are two types of polymorphism.
- Compile-time polymorphism or method overloading or static polymorphism or early binding
- Run-time polymorphism or method overriding or Dynamic polymorphism or late binding or dynamic binding
S.No. | Compile-time polymorphism or method overloading | Run-time polymorphism or method overriding |
1 | Method overloading is a mechanism in which a class contain more than one method with the same name but parameter is different is called method overloading. | Method overriding means that you can redefine a base class method in a derived class. overriding is process of modifying the inherited method. So in case of inheritance you only need to create method with same name in your child class which you want to override. |
2 |
|
|
OVERLOADING | OVERRIDING |
---|---|
It is performed at compile time. | It is performed at runtime. |
It is carried out within a class. | It is carried out with two classes having an IS-A relationship between them. |
Parameters do not remain the same in case of overloading. | The parameter must remain the same in case of overriding. |
You can perform overloading on static methods. | You cannot perform overriding on static methods. |
Overloaded methods use static binding. | Overridden methods use dynamic binding. |