Method signature in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Method signature in Java

Hi Folks. Today I have encountered a question (during a challenge): "What is the process of defining more than one method in a class differentiated by method signature". Let me remind, that signature is a composition made of: "In the Java programming language, a method signature is the method name and the number, type and order of its parameters. Return types and thrown exceptions are not considered to be a part of the method signature." The missleading and wrong answer says: "Function overloading". However, bare in mind that: "Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different. " Cheers

14th Dec 2018, 2:43 PM
Jakub Dubański
Jakub Dubański - avatar
11 Answers
+ 7
Why the question is wrong itself - because author did not think through the meaning of method signature itself. Anyway, the thread is here to make people aware of the meaning. Thanks for Your replies, good discussion! We have bunch of funny questions, but the point is to educate ourselves not to gain meaningless XP. Cheers!
14th Dec 2018, 6:13 PM
Jakub Dubański
Jakub Dubański - avatar
+ 4
Jakub Dubański I know my friend! Try to find something useful! 👍 You are welcome! 😊
14th Dec 2018, 3:15 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 3
My glossary says that a method is said to be overloaded when there are other methods, defined in the same class, or inherited (in the JLS sense) from some superclass, with the same name but a different method signature, i.e. different types and/or number of arguments. The answer is not wrong.
14th Dec 2018, 2:56 PM
nius
+ 3
Method signatures: As we already know very well, Java is an object-oriented language. As such, every method in Java belongs to some class instance (or a class itself in case of static methods), has visibility (or accessibility) rules, may be declared abstract or final, and so on. However, arguably the most important part of the method is its signature: the return type and arguments, plus the list of checked exceptions which method implementation may throw. https://www.sololearn.com/post/44876/?ref=app
14th Dec 2018, 3:09 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 3
Thanks Danijel Ivanović - it is not quite related, however very useful. Anyway, "process of defining more than one method in a class differentiated by method signature" is just called - class design.
14th Dec 2018, 3:13 PM
Jakub Dubański
Jakub Dubański - avatar
+ 3
Oh yeah, now I got it! Thanks!
14th Dec 2018, 5:49 PM
nius
+ 3
hello everybody, I find the discussion interesting and therefore I am looking in the SCJP Exam documentation from sun, ok it is a little bit older, but it is correkt with „method signature“ because the rules for overloading there are: 1) overloaded methods MUST change the argument list 2) overloaded methods CAN change the return type 3) overloaded methods CAN change the access modifier 4) overloaded methods CAN declare new or broader checked exceptions 5) a methods CAN be overloaded in the same class or in a subclass. method signature mean the method name and the number, type and order of its parameter and this is the MUST condition.
14th Dec 2018, 5:55 PM
asa22
+ 2
Thanks for reply. The answer is wrong, because method signature also consist of method's name. There was even an answer "none of mentioned". Please read again the quoted question. I think You have just skipped that part, because we both agree on function overloading definition.
14th Dec 2018, 3:07 PM
Jakub Dubański
Jakub Dubański - avatar
+ 2
Well, isn't the question asking about defining more than one method differentiated by method signature, not by method name?
14th Dec 2018, 3:10 PM
nius
+ 2
I agree and disagree. Class design is too wide an area encompassing all members and constructs... Maybe the answer could be: class design - specifically method overloading.
14th Dec 2018, 3:34 PM
nius
+ 2
Ok, verbose example of non-VM method signature: someMethod(int,double) anotherMethod(int,double) Both methods are with different signature (original question asks about having more than one method with different signature, so condition is fullfiled). Can we say it is method overloading? It is not. Another example: someMethod(int,int) someMethod(int,int,int). Different signatures and it is method overloading. The point is, that method signature is a technical term. Questions can not create assumptions.
14th Dec 2018, 4:17 PM
Jakub Dubański
Jakub Dubański - avatar