Page 601 - AP Computer Science A, 7th edition
P. 601
What will happen when this code is executed?
(A) A list of employees’ names and corresponding pay will be written to the screen.
(B) A NullPointerException will be thrown.
(C) A ClassCastException will be thrown.
(D) A compile-time error will occur, with the message that the
getName method is not in the Consultant class.
(E) A compile-time error will occur, with the message that an
instance of an Employee object cannot be created.
26. Consider an array arr that is initialized with int values. The following code segment stores in count the number of positive values in arr.
int count = 0, index = 0; while (index < arr.length) {
if (arr[index] > 0) count++;
index++; }
Which of the following is equivalent to the above segment?
int count = 0;
for (int num : arr) {
II
if (num > 0) count++;
I
}
int count = 0;
for (int num : arr) {
if (arr[num] > 0) count++;
}
int count = 0;