Polymorphism








Polymorphism is an important feature of OOP . It simply means 'one name many form' . It is the ability to take more than form .

There are basically two types of polymorphism.

(1) Compile Time (also knows as Early binding) .
(2) Run Time (also knows as Late binding) Polymorphism .

Compile Time Polymorphism

In Compile Time Polymorphism Object knows about itself at compile time. Overloading is a compile time polymorphism. In Overloading method should have same name with different arguments. Simple example of overloading is if you have scenario in which you want do sum of two or three number what ever user will pass. So you can create two methods with same name Sum and assign 2 and 3 arguments into it.

Run Time Polymorphism

In Run Time Polymorphism, Object does not know about itself at compile time it assigns all the properties and methods at runtime. Overriding or inheritance-based polymorphism are kind of polymorphism. Simple and very common example if you have a class shape which is inherited to Triangle, Square and Circle classes. Shape class has a method name as Draw which will definitely inherited to all inherited class. Now, if you declare a variable of shape class and initialize it with any of the inherited class it will call the method of inherited class.
Top
Clicky Web Analytics