The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
May 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.



Posted by Mekala on May 09, 2000 at 9:52 AM

> hi,
> Can we create a method in java having some arguments as optional?
> If possible how?.Your explanation with source code
> will be appreciated.
> Thank you

There is nothing like optional arguments i.e. you can't leave some of the arguments of the method in calling the method. If you do that JVM will throw MethodNotFoundException.

There is a we get benefit out of method overriding in which you define all the methods with the same name same return type but with different no.of arguments. You can set all the unwanted arguments to null /leave unhandled. JVM will choose in run time the appropriate method.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us