This is a practice test. The actual test may contain fewer or more
questions. The actual test may or may not supply you with other
materials (such as starter code).
B.
Suppose that the method name alternatingSum
from Question 1 was implemented
like so:
public static int alternatingSum(List<Integer> t) {
int sum;
/* code not shown here that assigns the correct value to sum */
return sum;
}
Suppose a client writes a main
method that includes the
following two lines of Java code:
List<Integer> aList = Arrays.asList(8, 9, 10, 11);
int sum = Practice1B.alternatingSum(aList);
The first line of code creates the list [8, 9, 10, 11]
,
and the second line of code calls the alternatingSum
method from Question 1.
The memory diagram illustrating the state of memory for the two lines of client code
is shown below.
What suitable values of a, b, and c would complete the memory diagram?
---------------------
| main method |
---------------------
aList 100| 300a |
sum 102| a? |
---------------------
| |
| |
---------------------
300| List object |
---------------------
| |
| |
---------------------
| alternatingSum |
---------------------
t 500| b? |
sum 502| c? |
---------------------