AP Multiple Choice Practice Test 1

1. What values do c and d respectively have after the following sequence of statements?
boolean a = true;
boolean b = false;
boolean c = (a || b) && !(a && b);
boolean d = c || (a && b || !(a && b || (a && !b)));
a. true,true
b. true,false
c. false,true
d. false,false
2. What is the value of the following expression?

100 % 24 / 3
a. 1.3333333333333
b. 0
c. 2
d. No answer - Division by Zero
e. 1
3. If a and b are variables of type boolean then which of the following exressions is true when exactly one of a and b is true, and false under all other circumstances?
a. a || b
b. a && b
c. (a && !b) && (!a && b)
d. (a || b) && (!a || !b)
e. (a || b) || (!a || !b)
4. You are writing a program to keep track of your audio CD collection, and are defining a class CD to represent a single compact disc. You are defining instance variables to store the title, number of tracks and cost of each CD.

What are the most appropriate types for those variables (in that or- der)?
a. String, double, String
b. String, int, int
c. String, int, double
d. String, int, boolean
e. boolean, String, String
5. Which of the following statements about constructors are true?

1. A class can have zero, one or more constructors.
2. Constructors can have zero, one or more parameters.
3. The constructor must have the same name as the class and no return type.

What are the most appropriate types for those variables (in that order)?
a. 1 and 2
b. 2 and 3
c. 1 and 3
d. 1, 2 and 3
e. 1 only
6. What is the value of the expression

10 + 5 * 4 / 3 - 13 % 3
a. 12.66666666666666
b. 15.666666666
c. 12
d. 16
e. 15
7. What are the respective values of the following two expressions?

4.0 * 7 / 2
4.0 * (7 / 2)

a. 14 6
b. 14 14
c. 14 12
d. 12 14
e. 12 12
8. What is the output of loop(8), where loop is defined as follows?

public void loop(int n) {
for (int i=0; i System.out.print(" ");
}
System.out.println();
}


a. 0 0 0 3 4 10 12 21
b. 0 1 3 6 10 15 21 28
c. 0 0 1 3 6 10 15 21
d. 0 3 4 10 12 21 24 36
e. 0 0 3 4 10 12 21 24
9. Given the following method (you may assume it has all compiled correctly so there are no syntax errors), what will be output?

public void printloop()
{
int i;
for (i=1; i<9; i++) ;
if (i%2 == 0) ;
System.out.print(i + " ");
System.out.println();
}


a. 2 4 6 8
b. 8
c. Nothing
d. 9
e. 2 4 6
10. If somebody's height in inches is stored in a variable h, then which of the following commands will correctly translate this into US-style feet-and-inches terminology (one foot contains 12 inches, so somebody who is 74 inches tall is usually said to be 6 feet and 2 inches.

a. int feet = h/12;
int inches = (h - feet*12)/12;
b. int feet = h % 12;
int inches = h;
c. double feet = h / 12;
int inches = h % 12;
d. int feet = h / 12;
int inches = h % 12;
e. int feet = h-12;
int inches = h/12;

The number you got right:       Percent Correct:       Letter Grade: