0

I read a book titled 'Object First with Java' and in page 7 the author mentioned that the method signature "provides information needed to invoke that method". And the the author gave the following example:

void moveHorizontal(int distance)

However, today when I was watching a video about C# on Pluralsight, the author said that "the return type of a method is not part of the method signature".

I'm confused now and would like know what is a method signature?

Saree
  • 21
  • 1
  • 2
  • 1
    [Google query](https://www.google.com.tr/search?q=What+is+a+method+signature%3F&ie=utf-8&oe=utf-8&gws_rd=cr&ei=3pQvVaC1AsyxsAHUtoLYDA) returns 9.400.000 results. Just saying.. You can also read Eric Lippert's answer. http://stackoverflow.com/a/8809191/447156 – Soner Gönül Apr 16 '15 at 10:54
  • [Defining Methods](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html) – Seelenvirtuose Apr 16 '15 at 10:57

2 Answers2

13

A method-signature is the part of the method based on which you overload / override it. It contains :

  1. The method name.
  2. The arguments passed to it.

It doesn't contain :

  1. Scope / access modifier
  2. return type.
TheLostMind
  • 35,966
  • 12
  • 68
  • 104
-1

Method signature is used in interfaces and in abstract classes, but we always define the method data type(return type). It will be something invaluable if the return type is not a part of the signature.