Which of the following shows the header for a method that will accept any number of int values? public static int add(int x) public static int add(int x, int y, int... z) public static int add(int...x) public static int add(int[] x)
@MDoodler
actually here I just took a screenshot of everything I have here.
what one you think?
I think it's the 3rd one
for the one you asked about
@bibby
@hartnn
Q4 is one of those tricky questions with several possible answers due to poor formulation. d) isn't technically wrong because passing an int array and dealing with it properly will allow the method to "... accept any number of int values ...". In this question they're however asking for a "... header for a method that will accept any number of int values ..." which means what they're really asking for is a header that accepts a variable amount of arguments. That feature is called varargs and you can read about the details in the links http://stackoverflow.com/questions/2330942/java-variable-number-or-arguments-for-a-method http://docs.oracle.com/javase/7/docs/technotes/guides/language/varargs.html
Nice! I haven't heard of that one before.. it'll come in handy.
Join our real-time social learning platform and learn together with your friends!