Method Overloading in Java


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

Source Code

public class OverloadingExample {
    static int add(int a, int b) {
        return a + b;
    }
    static double add(double a, double b) {
        return a + b;
    }
    public static void main(String[] args) {
        System.out.println(add(5, 10));
        System.out.println(add(5.0, 10.0));
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments