• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method Overloading: Urgent Help Needed  RSS feed

 
Ashish Chopra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

The following code specifies a class with two methods.

Class Load {
void loader(int loadval, int loadnum)
{
\\some implementation
}

int loader(float loadval,float loadnum)
{
\\some implementation
}

My question: Is This Overloading? Why/Why not?

Need this one very urgently....TIA
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashish,
Please have a look at this page. HTH.

Check the section "Distinguishing overloaded methods".
[ February 25, 2005: Message edited by: Srinivasa Raghavan ]
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My question: Is This Overloading? Why/Why not?


Yes. Two methods with the same name and different parameters.
A couple of points here.

1. The return types do not matter for overloading.

2. The first method would be called incase of a perfect match only. ie when you call loader() passing in 2 ints. Try calling the method with a int/short/byte/long and a short/byte/long/int or any possible combinations of this except int and int, you would find the second method being called though you dont have a method that accepts, for instance an int and a float.

ram.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!