2. POLYMORPHISM:-
IT IS DERIVED FROM THE GREEK
WORD POLUMORPHOUS
POLUS-MANY
MORPHE-SHAPE/FORM
“HAVING MULTIPLE FORM”
3. It is the ability for a
message or data to be
processed in more than one
form.
It is the property by which
the same message can be
sent to objects of several
different classes.
4. Example
The message send by ringing the bell in
school, is processed in many forms by which
we are informed about:-
The beginning of the class,
End of the class,
Beginning of an interval,
End of the day’s classes etc.
6. STATIC
POLYMORPHISM
Static polymorphism is also called as Compile
Time polymorphism. In Static polymorphism
methods are overloaded with same name but
having different signatures. So it is called as
method overloading.
7. Static or Compile Time Polymorphism:-
In static polymorphism, the decision is
made at compile time.
Which method is to be called is decided
at compile-time only.
Method overloading is an example of
this.
Compile time polymorphism is method
overloading, where the compiler knows
which overloaded method it is going to
call.
8. Example:
-
public class clsCalculation
{
public int Add(int a, int b)
{
return a + b;
}
public double Add(int z, int x, int c)
{
return z + x + c;
}
}
9. DYNAMIC
POLYMORPHISM
Dynamic polymorphism is also called as Run Time
polymorphism. In this type of polymorphism
methods have the same name, same signature but
different in the implementation.
In Dynamic polymorphism methods are overridden
so it also called as method overriding.
10. Dynamic or Runtime Polymorphism:
Method overriding allows us to have
methods in the base and derived classes
with the same name and the same
parameters.
By runtime polymorphism, we can point to
any derived class from the object of the
base class at runtime that shows the ability
of runtime binding.
11. Example:-
public class clsShape
{
public int _radius = 5;
public virtual double getArea()
{
return 0;
}
}
public class clsCircle : clsShape
{
public override double getArea()
{
return 3.14 * _radius * _radius;
}
}
public class clsSphere : clsShape
{
public override double getArea()
{
return 4 * 3.14 * _radius * _radius;
}
}
12. Polymorphism in c# is achieved
by:-
Function Overloading
Operator Overloading
Dynamic Binding
13. EARLY
BINDING
It refers to the ability of the compiler to relate
or bind a function definition during
compilation itself.
FUNTION OVERLOADING and
OPERATER OVERLOADING comes under
this category.
14. LATE
BINDING
It refers to the binding of a function call with
the function definition during Run-time.
It uses the concept of POINTERS and
INHERITENCE.