Java supports methods with variable number of arguments. Which of these options
ID: 3840092 • Letter: J
Question
Java supports methods with variable number of arguments. Which of these options is considered valid method declaration in Java when the following statement is executed?
myObj.variableArgsMethod(10, 20, 30, 40);
public void variableArgsMethod(Object...varargs) { . . . }
public void variableArgsMethod(String...varargs) { . . . }
public void variableArgsMethod(int...varargs) { . . . }
Options (a) and (b)
Options (a) and (c)
Options (b) and (c)
Options (a), (b), and (c)
None of the above
a.public void variableArgsMethod(Object...varargs) { . . . }
b.public void variableArgsMethod(String...varargs) { . . . }
c.public void variableArgsMethod(int...varargs) { . . . }
d.Options (a) and (b)
e.Options (a) and (c)
f.Options (b) and (c)
g.Options (a), (b), and (c)
h.None of the above
Explanation / Answer
answer is,
e. Options (a) and (c)
options (a) and (c) are valid . Option (b) is not valid. It will generate a error during compilation. Since, int cannot
be converted into String.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.