using method that take variable number of parameters
<p>I am trying to make a method that build new object of the class (PhoneBook)  using different constructors according to the number of parameters ,, but it  gives an error </p>

<p>(      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 )</p>

<pre><code>public static PhoneBook createObjects(String fName,String lName,String num,String...optional)
{
    n++;    
    if (optional[0]==null)
        ArrayOfObjects[n]=new PhoneBook(fName,lName,num);
    else if (optional[1]==null)
        ArrayOfObjects[n]=new PhoneBook(fName,lName,num,optional[0]);

    return ArrayOfObjects[n];   
}
</code></pre>
