Answer:
Polymorphism
Explanation:
Polymorphism is the ability of an object to take multiple forms. It is an important concept of Object Oriented Programming. Polymorphism is used in Object Oriented Programming when a reference of a parent class is used to refer to a child class object. It allows to perform a single action in different ways. For example a person can possess different characteristics at the same time. A person can be a father, husband, employee or student. The same person can have different behaviors in different circumstances.
Example:
Suppose there is class Animal with a procedure sound(). This method can have different implementation for different animals. For this purpose lets take two derived classes Cow and Cat that extend the Animal class (parent/base class). Now the method sound() can be used in different ways for Cow and Cat.
public class Animal{
public void sound(){
System.out.println("Animal is making a sound"); }
}
public class Cat extends Animal{
public void sound(){
System.out.println("Meow"); }
}
The output is Meow. The same method sound() is used for cat subclass.
public class Cow extends Animal {
public void sound(){
cout<<"Mooo"; }}
The output is Mooo. The method sound() is used for a Cow subclass which returns the sound of Cow in output.
So the same function i.e. sound() behaves differently in different situations which shows Polymorphism.
Polymorphism has 2 types.
One is compile time polymorphism which is called overloading. In method overloading a class can have more than one functions with same name but different parameters. Methods can be overloaded by change in number or type arguments. For example overloading a function method() can take the following forms in which the name remains the same and parameters are different.
void method(int a)
void method(float a)
void method(float a, float b)
Second type is run time polymorphism which is called overriding. Method overriding is when a method declared in derived class is already present in base class. In this way derived/child class can give its own implementation to base/parent class method. Method present in base class is called overridden and that in subclass is called overriding method. The example of Animal Cow and Cat given above is an example of overriding.