Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading Question?

 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OVERLOADING
Can a method who is Overloading another method can have less no.of parameters than the original method
For eg:
1)public int setVar(int a, int b, float c) { ...}
2) public float setVar(int a)
{
return a;
}
Can we say this as Overloading or is it that the overloading method should have the exact number of parameters that is there in the original method?
Please explain?
Sonir
 
Arathi Rajashekar
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sonir shah:
OVERLOADING
Can a method who is Overloading another method can have less no.of parameters than the original method
For eg:
1)public int setVar(int a, int b, float c) { ...}
2) public float setVar(int a)
{
return a;
}
Can we say this as Overloading or is it that the overloading method should have the exact number of parameters that is there in the original method?
Please explain?
Sonir

It can have less number of parameters. Actually what overloading is. It can have any number of parameters. Whether one or two or more. But the type of parameter and order should differ.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
two methods are overloaded when they have the same name but everything else may differ
HIH
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Valentin Crettaz:
two methods are overloaded when they have the same name but everything else may differ
HIH

well just to be nit-picky
public void foo(int a)
public int foo(int a)
This is a compiler error. The return type is not considered when determining if a method is overridden. You may change the return type, as long as something else is different in the signature as well

public void foo(int a)
public int foo(byte b)
protected String foo(int a, byte b)

Rob
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're perfectly right Rob...
I'm sorry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic