This Article will give you insights on how to create a variable argument method in java.
Variable argument method is mainly used when
- we are not aware of the number of arguments that are going to be passed at runtime.
- one method will perform same operations for 0 or more than 0 no. of arguments.
Variable arguments are declared as datatype followed by 3 dots : String…
Consider the following example:
Here the method varIntArgMethod() is a variable argument method which will accept integer arguments and perform summation on those variables.
Output for the above code :