2019 APCSA模拟题选择题
2019 APCSA模拟题选择题
1 of 22
AP CSA Practice Exam 2019
1) Suppose x, y and z are variables of type int. Consider the following three conditions
I. (x == y) && (y == z) && (x == z)
II. (x==y) || (y==z) && (x == z)
III. (x - y) * (x - z) * (y - z) == 0
2) Based on the diagram below, which of the following declarations will cause an error?
(A) I only
(B) II only
(C) Ill only
(D) I and II only
(E) II and Ill only
Pg. 2 of 22
3) Consider the following method.
4) An array of hospital records is sorted by patient ID numbers. Suppose a patient's record must be located,
given the patient's name only. Which of the following procedures is the most efficient for locating that patient's
record?
5) Which of the following code segments correctly stores in x a random real number such that 0.6< x < 1?
Pg. 3 of 22
6) Suppose methods f1 and f2 are defined as follows:
(A) -4
(B) 4
(C) 6
(D) 8
(E) -6
7) Consider the following static method, countDiff. Method countDiff is intended to count the number of
different values in array arr. It does not, however, work as intended.
Pg. 4 of 22
Which of the following changes should be made so that countDiff will work as intended?
(B) The constructor in a subclass must use the keyword super to initialize the
(E) If a subclass does not explicitly provide a constructor and its superclass has
just one constructor with a parameter, an error will occur when an attempt is
(A) 10
(B) 12
(C) 16
(D) 26
(E) 32
11) Suppose a and b are boolean variables. The expression will evaluate to false whenever
A) I only
B) II only
C) Ill only
{
y *= 2;
if (y % x == 1)
y += x;
}
x = x -3;
}
System.out.println(x + " " + y);
(A) 1 6
(B) 7 12
(C) -3 12
(D) 4 12
(E) -3 6
int result = 13 - 3 * 6 / 4 % 3;
(A) -5
(B) 0
(C) 13
(D) -1
(E) 12
Pg. 7 of 22
14) Consider the following code segment. Assume k is some positive integer
greater than 2. How many times will “SMALL” be printed?
(A) 0
(B) 1
(C) k - 1
(D) k - 2
(E) k
15) Assuming that both Bird a nd Sparrow have default constructors, which is (are) valid?
I. Flyer f1 = new Bird();
II. Bird b = new Sparrow();
III. Flyer f2 = new Sparrow();
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III
(A) I only
(B) II only
(C) III only
(D) II and III only
(E) I, II, and III
Pg. 9 of 22
19) The elements of an array arr are to be sorted in increasing order. Which represents the first step of a merge
sort algorithm?
(A) Find the smallest element in arr and swap it into arr[0] .
(B) Compare arr[0] with arr[1] and, if necessary, shift and replace elements such that arr[0] is less than
arr[1] .
(C) Compare arr[0] with the middle element of arr, arr[mid] , and if arr[0] is less than arr[mid] , swap these
elements.
(D) Compare the first and last elements, and if the first is less than the last, swap these elements.
(E) Break the array into roughly two equal halves.
(B) return 8 * n;
(C) return 64 * n;
(D) return (int) Math.pow(n,4);
(E) return (int) Math.pow(n,8);
21) Consider the following program that changes a 2D array mat of type int
What is printed?
(A) run eat
(B) run eat sleep
(C) run eat sleep bark
(D) run eat bark sleep
(E) Nothing is printed due to infinite recursion.
Pg. 15 of 22
(D) 7
(E) 8
28) Under what condition will an ascending (lowest to highest) insertion sort execute faster?
(A) The elements are in random order
(B) The elements are in sorted in descending order.
(C) The elements are integers
(D) Best case, average case, and worst case are all the same.
(E) The elements are already sorted in ascending order.
What are the values for changerObj.str and chngerObj.n that are printed after this code executes?
str n
(A) world 6
(B) worldpeace 6
(C) world 12
(D) worldpeace 12
(E) peace 12
31) When is the following Boolean expression true (a and b are integers)?
(a < b) && !(b > a)
A) It is always true
B) It is never true
Pg. 18 of 22
C) When a = b
D) When a < b
E) When a > b
32) Which of the following reasons for using an inheritance hierarchy are valid?
I. Methods from a superclass can be used in a subclass without rewriting or copying code.
II. Objects from subclasses can be passed as arguments to a method designed for the superclass
III. Objects from subclasses can be stored in the same array
IV. All of the above
V. None of the above
A) I and II
B) I and III
C) IV
D) V
E) I only
33) Which of the following code segments is equivalent to the code below?
if (x >= 1) x = x * 3;
if (x > 3) x = 0;
A) x = 0;
B) if (x > 1) x = 0;
C) if (x > 3) x = 0;
D) if (x >=1) x = 0;
E) none of the above
Pg. 19 of 22
35) Which of the following correctly shows the iterations of an ascending (from left to right) selection sort on
an array with the following elements: {6,3,8,5,1}?
A) {3,6,8,5,1}, {3,5,6,8,1}, {1,3,5,6,8}
B) {1,3,8,5,6}, {1,3,8,5,6}, {1,3,5,8,6}, {1,3,5,6,8}
C) {3,6,8,5,1}, {3,6,8,5,1}, {3,5,6,8,1}, {1,3,5,6,8}
D) {1,3,8,5,6}, {1,3,5,8,6}, {1,3,5,6,8}
E) {1,6,3,8,5}, {1,3,6,8,5}, {1,3,5,6,8}
D) omp
E) Om
37) Consider an array arr and a list list that is an ArrayList<String>. Both arr and list are initialized with string
values. Which of the following code segments correctly appends all the strings in arr to the end of list?
I. for(String s : arr)
list.add(s)
II. for(String s : arr)
list.add(list.size(),s);
III. for(int i = 0; i < arr.length; i++)
list.add(arr[i]);
(A) I only
(B) II only
(C) III only
(D) I and III only
(E) I, II, and III
(B) 9
(C) 12
(D) 27
(E) 81
40) Consider the following method. What is the output from conditionTest(3,-2)?
if (num1>num2)
System.out.println("A");
else
System.out.println("B");
System.out.println("C");
System.out.println("D");
else {
System.out.println("E");
A) A
B) B
C) C
D) D
E) E