Back to Java Notes
Topic #59

Java Method Overloading


Method Overloading

With method overloading, multiple methods can have the same name with different parameters:

Example

int myMethod(int x)
float myMethod(float x)
double myMethod(double x, double y)

Consider the following example, which has two methods that add numbers of different type:

Example

static int plusMethodInt(int x, int y) {
  return x + y;
}

static double plusMethodDouble(double x, double y) {
  return x + y;
}

public static void main(String[] args) {
  int myNum1 = plusMethodInt(8, 5);
  double myNum2 = plusMethodDouble(4.3, 6.26);
  System.out.println("int: " + myNum1);
  System.out.println("double: " + myNum2);
}

Instead of defining two methods that should do the same thing, it is better to overload one.

In the example below, we overload the plusMethod method to work for both int and double:

Example

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);
}

Note: Multiple methods can have the same name as long as the number and/or type of parameters are different.

Want to go beyond the notes?

Join Coding Now Tech Institute's Java course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Java Method Overloading – FAQs

Quick answers about learning Java Method Overloading in Java.

This free note from Coding Now Tech Institute explains Java Method Overloading in Java — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Java topic on Coding Now Tech Institute, including Java Method Overloading, is 100% free with no signup required.
With focused practice, most students grasp Java Method Overloading in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now