Varargs method invocation
# Topic
Arrays as parameters
# Problem
Varargs method invocation
You are given a method with the following declaration:
public static int method(int[] array, int... vararg) { return 1; }
1
Select all correct ways to invoke this method.
[x] method(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 });
[ ] method(1, 2, 3);
[x] method(new int[] { 1, 2, 3 });
[x] method(new int[] { 1, 2, 3 }, 4, 5);
[ ] method();
1
2
3
4
5
2
3
4
5
Correct.
# Hint & Explain
U can pass also nothing to the vararg argument
Vararg accepts both a sequence of integers and an array of integers.
编辑 (opens new window)
上次更新: 2022/09/25, 10:41:23