• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overloading Question?

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
two methods are overloaded when they have the same name but everything else may differ
HIH
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you're perfectly right Rob...
I'm sorry
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic