File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading Question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading Question?" Watch "Overloading Question?" New topic
Author

Overloading Question?

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
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

Joined: Nov 20, 2001
Posts: 112
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.


Arathi<br />Sun Certified Java Programmer
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
two methods are overloaded when they have the same name but everything else may differ
HIH


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
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


Rob
SCJP 1.4
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
you're perfectly right Rob...
I'm sorry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading Question?