• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method overloading

 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10509
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so only different return types won't suffice right?
 
Winston Gutkowski
Bartender
Pie
Posts: 10509
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swapnil Dharane wrote:so only different return types won't suffice right?

Right.

Winston
 
BalaMurali dhar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when two or more methods having same name , same class but different arguments that is called method overloading
 
Panagiotis Kalogeropoulos
Rancher
Posts: 99
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Language Specification would define those method signatures as main(String[]) and main(String...) respectively, missing out the parameter names.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic