Method Overloading in Java


Method overloading allows you to have multiple methods with the same name but different parameters.

Source Code

public class Main {
    static int plusMethod(int x, int y) {
        return x + y;
    }
    static double plusMethod(double x, double y) {
        return x + y;
    }
    public static void main(String[] args) {
        int myNum1 = plusMethod(8, 5);
        double myNum2 = plusMethod(4.3, 6.26);
        System.out.println("int: " + myNum1);
        System.out.println("double: " + myNum2);
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments