Tuesday, August 15, 2017

Polymorphism

Method overloading is called polymorphism. In a class, there are multiple functions with the same name but definition of function are different from each other. That means parameter should be different from each other. Argument number or type should be different in method overloading. Their function overloading not possible if return type only different.

Example:

class Country
{
    public static float Dhaka(int number1, int number2)
    {
        return Dhaka(number1, number2, 0);
    }

    public static float Dhaka(int number1, int number2, int number3)
    {
        return Dhaka(number1, number2, number3, 0);
    }

    public static float Dhaka(int number1, int number2, int number3, int number4)
    {
        return number1 + number2 + number3 + number4;
    }
}

No comments:

Post a Comment