Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can changes in the order of the method parameters be called method overloading?

Please note that only order of the parameters are changed in below example. So my question is - Can we call below example is of method overloading?

public void show(String s, int a){
    System.out.println("Test.show(String, int)");
}
public void show(int s, String a){
    System.out.println("Test.show(int, String)");
}
like image 900
Juns Avatar asked Sep 03 '13 17:09

Juns


People also ask

Can we overload a method by changing the order of the parameters?

Method overloading can be done by changing: The number of parameters in two methods. The data types of the parameters of methods. The Order of the parameters of methods.

Does order of parameters matter in method signature?

The order of the parameters make a difference because it is a different signature. Imagine you had a human signature and altered the order of the letters, it would no longer be the same signature.

What is parameter in method overloading?

Method overloading means two or more methods have the same name but have different parameter lists: either a different number of parameters or different types of parameters. When a method is called, the corresponding method is invoked by matching the arguments in the call to the parameter lists of the methods.

Does order of parameters matter in java?

Answer. No, the order of query parameters should not matter.


1 Answers

Yes, that's absolutely method overloading.

From section 8.4.9 of the JLS:

If two methods of a class (whether both declared in the same class, or both inherited by a class, or one declared and one inherited) have the same name but signatures that are not override-equivalent, then the method name is said to be overloaded.

"Override-equivalent" is described in section 8.4.2:

Two methods have the same signature if they have the same name and argument types.

[ ... Details on "same argument types ... ]

The signature of a method m1 is a subsignature of the signature of a method m2 if either:

  • m2 has the same signature as m1, or

  • the signature of m1 is the same as the erasure (§4.6) of the signature of m2.

Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.

like image 127
Jon Skeet Avatar answered Oct 09 '22 21:10

Jon Skeet