- Polymorphism is utilized to expect the capacity of a few various structures. Or then again we can say performing one assignment in various manners.
- In java + administrator is utilized for expansion too to connect (join) strings. Here a solitary administrator is doing two unique things depending upon the kind of contention, so it is the circumstance of polymorphism.
Kinds of Polymorphism
Order Time Polymorphism
- At the point when the usefulness of an article bound at incorporate time, it is known as incorporate time polymorphism.
- Accumulate time polymorphism is of two kinds, administrator over-burdening what’s more, technique over-burdening.
- Java doesn’t bolster administrator over-burdening, it just helps technique over-burdening.
Note: It is given in java language detail that java doesn’t
support aggregate time polymorphism, strategy over-burdening is likewise bolstered at technique abrogating.
Runtime Polymorphism
- At the point when the usefulness of an article bound at runtime, it is
- known as runtime polymorphism.
- Strategy abrogating is the case of runtime polymorphism.
Strategy Overloading
At whatever point we keep more than one strategy for the same name however
distinctive in the model in a class, it is known as technique over-burdening.
Strategy over-burdening is accomplished when:
1. Number of contentions are extraordinary
void show(int a);
void show(int an, int b);
2.Number of contentions same yet extraordinary in information type
void show(int a);
void show(float a);
void show(long a);
A program to show strategy over-burdening is given beneath.
class demo
{
void show(int a)
{
System.out.println(“int”);
}
void show(float a)
{
System.out.println(“float”);
}
void show(long a)
{
System.out.println(“long”);
}
public static void main(String…s)
{
demo d = new
demo();
d.show(10);
d.show(10.0F);
d.show(10L);
}
}
Output
method overriding
At whatever point parent and kid class have the same method, it is
known as method overriding.
class base
{
void
show()
{
System.out.println(“base”);
}
}
class child extends base
{
void
show()
{
System.out.println(“child”);
}
public
static void main(String…s)
{
child
c=new child();
c.show();
}
}
Output
On the off chance that you have any uncertainty in above instructional exercise, at that point you can inquire your inquery