Polymorphism
One Name and many forms,
Polymorphism is one of the fundamental concepts of OOP.
Polymorphism is of two
types:
1. Compile time
polymorphism/Overloading
2. Run time polymorphism/Overriding
Compile
time polymorphism/Overloading (early binding):
In this type of
polymorphism, compiler at compile time
identifies which form it has to execute
There are few advantages
of compile time polymorphism:
Advantage of early binding
is execution will be fast. Because every thing about the method is known to
compiler during compilation it self
But disadvantage is lack
of flexibility.
Eg: Method Overloading
Operator
Overloading
Run time polymorphism/Overriding (Late binding):
In this type of
polymorphism, compiler at Run time
identifies which form it has to execute
There are few advantages
of run time polymorphism
Advantage of Late binding
is execution will be slow. Because every thing about the method is known to
compiler during run time
Example of Run time Polymorphism is:
Interface
Method overriding
Examples of early binding
are overloaded methods, overloaded operators and overridden methods that are
called directly by using derived objects.
Comments
Post a Comment