Tuesday, 29 November 2016

Facts about Variable Length Argument in Java

Variable Length Argument Rules in Java


                 Java included a feature that simplifies the creation of methods that require variable number of arguments. This is known as vararg. vararg is the short for of Variable Length Arguments.

5 Facts about Variable Length Argument Rules in Java


1. A variable-length argument is specified by three periods (…).

     Eg:

            static void TestVariableArgument(int ... v) {
            }

         This syntax tells the compiler that TestVariableArgument( ) can be called with zero or more arguments.

2. In the case of no arguments, the length of the array is zero.

3. A method can have “normal” parameters along with a variable-length parameter and the variable-length parameter must be the last parameter declared by the method.


4. Overloading a method that takes a variable-length argument is possible.

5. If a method call conflicts with two methods that implements variable argument or other leads to error. 

3 comments :

  1. Needed to compose one simple word yet thanks for the suggestions that you are contributed here, would like to share to my friends...
    Best Online Software Training Institute | Core Java Training

    ReplyDelete
  2. Thank You for sharing informative variable facts...

    ReplyDelete
  3. This article is well written and quite informative.
    More articles should be written and you have just found a follower.and more visit.
    quickbooks training in hyderabad

    ReplyDelete