Methods, like variables, are given unique names. Trying to create a second identical method as another method in your class would cause an error. However, if the parameters are different, a method name can be reused. This process is called Method Overloading.
Valid/Invalid Overloading
Only certain changes to a method declaration allow a method to be overloaded. Consider the following four cases:
Case 1: The number of parameters is different(valid)
public static int myMethod(int x, int y)
{
}
public static int myMethod(int x)
{
}
Case 2: The data type of parameters is different(valid)
public static int myMethod(int x)
{
}
public static int myMethod(double x)
{
}
Case 3: The variable letter is different(Invalid)
public static int myMethod(int x)
{
}
public static int myMethod(int y)
{
}
Case 4: The return type is different(Invalid)
public static int myMethod(int x)
{
}
public static void myMethod(int x)
{
}