-The explanation for option 4 says that, "The ... syntax is not applicable for return type". My question is how does one specify a varargs return type? Do I just put an array is the return type or is there another way to do this?
You can't have var args as return type. A method can return only one thing. Otherwise, how will you assign the return value ? Something like :
Object retvalue = methodX(); //if methodX returns multiple value, which value will you assign to retvalue?
If you want to return multiple things, you can return an array or a collection. For example,
Object[] relvalue = methodX();//methodX returns one object i.e. one value, which happens to be an array.
ArrayList relvalue = methodX();//methodX returns one ArrayList object, which may contain multiple objects.
Thanks for the explanation. I guess that it is almost impossible to return a varargs to something.
A primitive variable obviously can not take more than one value. It seems like an ArrayList could though since its size can expand unlike an Array, which is fixed.
I will just have to remember varargs is not a valid return type for Java.