aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 31
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: 7043
    
  16

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?
Artlicles by Winston can be found here
Swapnil Dharane
Ranch Hand

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

Joined: Mar 17, 2011
Posts: 7043
    
  16

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: 36478
    
  16
The Java Language Specification would define those method signatures as main(String[]) and main(String...) respectively, missing out the parameter names.
 
jQuery in Action, 2nd edition
 
subject: method overloading
 
Similar Threads
Overloading and Method Signatures
Method Overloading and overriding
Need help for method selection
Varargs . . . what are they for?
i have no idea at all