aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assigning default values to function arguments...possible in java ? 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 "Assigning default values to function arguments...possible in java ?" Watch "Assigning default values to function arguments...possible in java ?" New topic
Author

Assigning default values to function arguments...possible in java ?

Chet Arora
Greenhorn

Joined: May 20, 2003
Posts: 29
Hi,

I just needed to know if its possible to assign default values to function arguments in java.
For instance in C,
we may define a funtion like:
void Data(int i, int j=0)
{
...
...
}
Now, while calling the function Data, we dont necessarily need to pass the second argument (using say Data(10) or something is perfectly ok). Is there any equivalent in Java ?

Thanks,
Chetan
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
I just needed to know if its possible to assign default values to function arguments in java.

The easiest way to answer this question is to open a text editor (or your favorite IDE) and try it yourself.

let me know your results


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Chet
I guess this is not allowed in java. You can use method overriding in java instead.
Chet Arora
Greenhorn

Joined: May 20, 2003
Posts: 29
Andres,
I get the point. That piece of code wont compile. If it did it would probably put function overloading in jeopardy.

Anupam,
You probably meant function overloading.
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Yes I mean method overloading.
 
Don't get me started about those stupid light bulbs.
 
subject: Assigning default values to function arguments...possible in java ?