Wim Vanni wrote:In what situation would you want that?
It is possible to have an undefined number of arguments if you make use of arrays (or collections).
Actually i was asked this question in interview, so even i don't have any idea that in what type of situation they want.
Rob Spoor wrote:Or use varargs, available since Java 5.0. These arguments must be all of the same type (or at least have a common super type), the varargs parameter must be the last parameter of the method, and there can be only one varargs parameter per method. Inside the method you treat the parameter as if it's an array. For instance:
Thanks for the reply Rob.
The Same answer came into my mind. But if there are different types of arguments and we want to add another different type of argument.
e.g. void TestMethod(int arg1, char arg2) and what if i want to add string argument at runtime (e.g. void TestMethod(int arg1, char arg2, String arg3))
what i think is it's not possible but even i want to clear this confusion.