Method Overloading - Rybd04/2143-OOP GitHub Wiki

Definition

Method Overloading

When two or more methods in the same class have the same name but different parameter signatures (i.e., different types or number of arguments).

Explanation

Multiple methods in the same class have the same name but different parameters. The correct method is chosen at compile time.

Basic Code Example

class MathUtils {
    int add(int a, int b) {
        return a + b;
    }

    double add(double a, double b) {
        return a + b;
    }

    int add(int a, int b, int c) {
        return a + b + c;
    }
}

Image

image

Additional Resources

https://www.geeksforgeeks.org/method-overloading-in-java/ https://www.w3schools.com/java/java_methods_overloading.asp