Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method signature

 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathy and Bert and all the ranchers
I have read some books answer following
The method signature including
The name of the method and
The parameter list of the method
But without the return type
Does the method signature including the return type?
For Kathy and Bert
Does the book contain both of your signature as well if I win the book?
Because I can not go to the book shop which both of you will be there.
thanks for your attention
 
Kevin Gilchrist
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The signature depends on whether you're overriding or overloading the methods.
The difference is described on one of the Sun tutorials as:
"Overloading and Overriding
As you construct classes and add methods to them, there are circumstances when you will want to reuse the same name for a method. There are two ways that you can do this with Java. Reusing the same method name with different arguments and perhaps a different return type is known as overloading. Using the same method name with identical arguments and return type is known as overriding. "
The full article is at:
http://developer.java.sun.com/developer/Books/certification/page3.html
[ June 04, 2003: Message edited by: Kevin Gilchrist ]
 
Greedy thomas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Siu
A short answer to your question about method signature. Yes - The method signature does include the return type.
Rajesh
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return type is not part of the signature.
JLS 15.12.2:
The second step searches the class or interface determined in the previous step for method declarations. This step uses the name of the method and the types of the argument expressions to locate method declarations that are both applicable and accessible, that is, declarations that can be correctly invoked on the given arguments. There may be more than one such method declaration, in which case the most specific one is chosen. The descriptor (signature plus return type) of the most specific method declaration is one used at run time to do the method dispatch.
The return type is part of the method descriptor, but not part of the method signature.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Original post of the following
hum....
I am not sure the signature of method overloading

Let me show some example why I confuse
1: void getRid(int i,int j);
2: void getRid(int i,float j);
3: int getRid(int i,float j);
4: int getRid(int i,int j);
If all of the four methods put in the interface,does the compiler give me an error message? It means that ARE all of the four methods are different.
But my teacher material show me that the method overloading only includes the name of the method and the parameter list of the method , IS this material WRONG
thanks again

After Michael answer
now without any doubts
thanks
The first time edit
[ June 04, 2003: Message edited by: siu chung man ]
The second time edit
thanks Layne
I am busy(exam including Java) within two weeks,so I am lazy that without using compiler
[ June 04, 2003: Message edited by: siu chung man ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your teacher is correct: only the name and parameters are part of the signature. As stated earlier, the return type is NOT part of the signature. If you put all four of the example methods you posted into the same class or interface, the compiler will complain. (Go ahead and try it for yourself.)
HTH
Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic