Consider array items, which contains the values 0,2,4,6, and 8. If method changeArray is called with the
method call changeArray (items, items[2]), what values are stored in items after the method has finished
executing?
public static void changeArray(int[] passedArray, int value)
{
passedArray[value] = 12;
value = 5;
}
A. 0,2,4,6,5
B. 0,2,5,6,12
C. 0,2,4,6,12
D 0,2,12,6,8 - Answers C. 0,2,4,6,12
An argument type followed by a(n) ___________ in a method's parameter list indicates that the method
receives a variable number of arguments of that particular type.
A. Square Brackets ([])
B. Ellipsis (...)
C. Varargs keyword
D. All of the above - Answers B. Ellipsis (...)
Which of the following statements is false?
A. When an argument is passed by reference, the called method can access the argument's value in the
caller directly but cannot modify it.
,B. To pass an object reference to a method, simply specify in the method call the name of the variable
that refers to the object.
C. To pass an individual array element to a method, use the indexed name of the array.
D. All arguments in Java are passed by value. - Answers A. When an argument is passed by reference,
the called method can access the argument's value in the caller directly but cannot modify it.
Consider the code segment below. Which of the following statements is false?
int[] g;
g = new int[23];
A. The first statement declares an array reference
B. The second statement creates the array
C. g is a reference to an array of integers.
D. The value of g[3] is -1 - Answers D. The value of g[3] is -1
Which of the following statements is true?
A. When a try block terminates, any variables declared in the try block are preserved.
B. You can have many catch blocks to handle different types of exceptions.
C. The try block contains the code that handles the exception if one occurs.
D. The catch block contains the code that might throw an exception. - Answers B. You can have many
catch blocks to handle different types of exceptions.
Which of the following sets of statements creates a multidimensional array with 3 rows, where the first
row contains 1 value, the second row contains 4 items and the final row contains 2 items?
A. int[][] items;
items = new int [3][?];
items[0] = new int[1];
, items[1]1 = new int[4];
items[2] = new int[2];
B. int[][] items;
items[0] = new int[1];
items[1]1 = new int[4];
items[2] = new int[2];
C. int[][] items;
items = new int [?][?];
items[0] = new int[1];
items[1]1 = new int[4];
items[2] = new int[2];
D. int[][] items;
items = new int [3][ ];
items[0] = new int[1];
items[1]1 = new int[4];
items[2] = new int[2]; - Answers D. int[][] items;
items = new int [3][ ];
items[0] = new int[1];
items[1]1 = new int[4];
items[2] = new int[2];
Which of the following tasks cannot be performed using an enhanced for loop?
A. Incrementing the value stored in each element of the array
B. Displaying all even element values in an array.
C. Calculating the product of all the values in an array.