permaculture playing cards*
The moose likes Beginning Java and the fly likes method overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method overloading" Watch "method overloading" New topic
Author

method overloading

Swapnil Dharane
Ranch Hand

Joined: Apr 22, 2012
Posts: 34
Hi all
i have a doubt regarding method overloading
Let's say we have two methods with same name,same number and type of arguments but with different return types.Will it be a case of method overloading ?

And if not, please tell whether method overloading solely depends upon method arguments (i.e. type and number of arguments) or not?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7525
    
  18

Swapnil Dharane wrote:i have a doubt regarding method overloading
Let's say we have two methods with same name,same number and type of arguments but with different return types.Will it be a case of method overloading ?

In the same class: Not allowed, as far as I know, so the question is moot.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Swapnil Dharane
Ranch Hand

Joined: Apr 22, 2012
Posts: 34
so only different return types won't suffice right?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7525
    
  18

Swapnil Dharane wrote:so only different return types won't suffice right?

Right.

Winston
BalaMurali dhar
Ranch Hand

Joined: Apr 14, 2012
Posts: 60
when two or more methods having same name , same class but different arguments that is called method overloading
Panagiotis Kalogeropoulos
Rancher

Joined: May 27, 2011
Posts: 99

Each method in Java has a "signature" which identifies its uniqueness. The signature is comprised of the name and the types of the parameters. For instance, in the method:



the signature is the name (main) and the parameters (String[] args). So if you want to overload a method, you must keep the same name and change the parameters. As a small exercise, will I be able to overload

with

??

You can learn more for this subject here:

http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
Panagiotis Kalogeropoulos
Rancher

Joined: May 27, 2011
Posts: 99

when two or more methods having same name , same class


When you say same class, you mean the class that encloses the method? If that is what you mean, it is redundant because we are referring to the same class - there is no point to discuss about overloading in different classes.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
The Java Language Specification would define those method signatures as main(String[]) and main(String...) respectively, missing out the parameter names.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method overloading
 
Similar Threads
Method Overloading and overriding
Varargs . . . what are they for?
Overloading and Method Signatures
i have no idea at all
Need help for method selection