1. What does the following code do when it is executed?
2. The output of the following code would be exactly 0.33.
3. Consider the following class. Which of the following code segments would successfully create a new Book object?
4. Given the PocketMoney class definition below, what is the output of the code in the main method?
5. Which of the following expressions is equivalent to !(c || d) ?
6. Which of the following is equivalent to the code segment below?
7. How many @ signs are output when the following code is executed?
8. Which of the following statements is a valid conclusion. Assume that variable b is an array of k integers and that the following is true:
9. Consider the following code segment. Which of the following statements best describes the condition when it returns true?
10. Assume that numList has been initialized with the following Integer objects: [5, 7, 8, 12]. Which of the following shows the values in numList after a call to mystery(11)?
private List numList;
public void mystery(int value)
{
int i = 0;
while (i < numList.size() && numList.get(i) < value)
{
i++;
}
numList.add(i, value);
}
[5, 7, 8, 11, 12]
[5, 7, 8, 12]
[5, 7, 8, 12, 11]
[11, 5, 7, 8, 12]
11. Given the following code segment, what is the value of sum after this code executes?
int[][] matrix = { {1,1,2,2},{1,2,2,4},{1,2,3,4},{1,4,1,2}};
int sum = 0;
int col = matrix[0].length - 2;
for (int row = 0; row < 4; row++)
{
sum = sum + matrix[row][col];
}
8
4
9
12
12. What are the contents of xyz after the following code segment has been executed?
int [][] xyz = new int [4][3];
for (int row = 0; row < xyz.length; row++) {
for (int col = 0; col < xyz[0].length; col++) {
if (row < col)
xyz[row][col] = 1;
else if (row == col)
xyz[row][col] = 2;
else
xyz[row][col] = 3; } }
{ {2 1 1 1}, {3 2 1 1}, {3 3 2 1}}
{ {2 1 1}, {3 2 1}, {3 3 2}, {3 3 3}}
{ {1 1 1 1}, {2 2 2 2}, {3 3 3 3}}
{ {2 3 3}, {1 2 3}, {1 1 2}, {1 1 1}}
13. Given the following class declarations and code, what is the result when the code is run?
14. Given the following method declaration, what value is returned as the result of the call func(5)?
15. Given the following method declaration, what value is returned as the result of the call consume(5)?