2020 Practice Exam MCQ
2020 Practice Exam MCQ
2020 Practice Exam MCQ - Review Ticket
2020 Practice Exam FRQ - Score
17/40
Corrections:
Q#: 4
- The correct answer should be D because since a<10 evaluates to true, the body of the if statement is executed.
Q#: 5
- The correct answer should be E because the constructor has the same signature as the existing constructor (String, String, boolean). A compiler error will occur.
Q#: 7
- The correct answer should be E because in the body of the first if clause in the code segment, b1 retains the value true if num is between 0 and 100, exclusive. In the body of the else clause, b1 retains the value true if num is less than -100.
Q#: 11
- The correct answer should be C because during the first iteration of the while loop, num is decremented and ”9” is printed. During the second iteration, num is decremented and ”8” is printed. This continues until the last iteration of the loop, when num is decremented and ”1” is printed.
Q#: 13
-
The correct answer should be D because by the De Morgan’s laws, !(a && b) is equivalent to !a !b and the entire expression is equivalent to !a !b c.
Q#: 14
- The correct answer should be D because the code segment I uses multi-way selection to assign and return the correct category. Code segment II returns ”rural” for all values of density because it uses a series of one-way selection statements instead of multi-way selection.
Q#: 16
- The correct answer should be B because the recursive call of the stars method occurs before any output is printed, so the method call stars(5) results in a recursive call to stars(4), then to stars(3), then to stars(2), and finally to stars(1).
Q#: 17
- The correct answer should be D because since j is instantiated as a SuperHero object, the j.powerUp(10) method call accesses the subclass method. The subclass method uses the super keyword to access the superclass method with the parameter 20.
Q#: 21
- The correct answer should be D because the method assigns the shortest string that occurs in any element of arr between arr[n] and arr[arr.length - 1], inclusive, to result[n]. The shortest string found between arr[0] and arr[3] is ”of”, so result[0] is assigned the value ”of”. The shortest string found between arr[1] and arr[3] is also ”of”, so result[1] is also assigned the value ”of”.
Q#: 22
- The correct answer should be A because in the line 12 is executed each time the variable sm is updated because a new smallest value is found. When j has the value 0, sm is updated for ”day” and ”of”. When j has the value 1, sm is updated for ”of”. When j has the value 4, sm is updated for ”year”.
Q#: 23
- The correct answer should be D because the outer for loop stores each row of the two-dimensional array in j, a one-dimensional array. The inner for loop stores each element of j in k and prints k.
Q#: 26
- The correct answer should be C because there are m * n iterations of the for loop in code segment I. In code segment II, the outer loop executes m times and the inner loop executes n - 1 times for each iteration of the outer loop. There are m * n - m iterations of the inner loop in code segment II, so ”A” is printed m more times than ”B” is printed.
Q#: 28
- The correct answer should be B because the method abMethod(String a, String b) removes all non-overlapping occurrences of string b from string a and returns the resulting String. It does this by repeatedly setting x to the index of an occurrence of b in a, then assigning a the result of the concatenation of the parts of a before and after the occurrence of b.
Q#: 29
- The correct answer should be E because the result of the method call calcMethod(16) is 16 + calcMethod(8). The result of the method call calcMethod(8) is 8 + calcMethod(4). The recursive calls continue until the call calcMethod(0), which returns the value 10.
Q#: 31
- The correct answer should be A because in the code segment I, i takes on the values -1 through nums.length - 2, inclusive, in the while loop. Since i is incremented before the if statement, the array elements nums[0] through nums[nums.length - 1] are compared to 0. In code segment II, array element nums[0] is excluded since the first iteration of the for loop accesses nums[1]. In code segment III, the variable i represents an element of the array rather than an index.
Q#: 32
- The correct answer should be B because since obj is instantiated as a ClassB object but the showValue method is not defined in ClassB, the showValue method call accesses the showValue method in the superclass, ClassA. Since the getValue method is defined in ClassB, the getValue method call accesses the getValue method in the subclass, ClassB, and ”B” is printed.
Q#: 33
- The correct answer should be E because the code segment performs a column-major traversal of the array, beginning with the second column and the second row. For each column, all values in that column after the value in the first row are printed on a single line. The println method call causes data from subsequent columns to appear on new lines in the output.
Q#: 34
- The correct answer should be E because when the element at position i is removed from numList, subsequent elements are shifted left. After the removal, the element that used to be at position i + 1 is now at position i. Because the method increments i regardless of whether the element at position i was removed, the method does not always work as intended.
Q#: 36
- The correct answer should be D because the body of the for loop in methodOne is executed a / b times. The body of the while loop in methodTwo is executed a / b times only when a % b is equal to 0. When a % b is not equal to 0, the body of the while loop in methodTwo is executed an additional time. For example, when a has the value 11 and b has the value 5, a / b evaluates to 2 and the for loop is executed two times but the while loop is executed three times.
Q#: 37
- The correct answer should be E because each iteration of the while loop adds num2 to num1 and then increments num2. The last value assigned to num2 and added to num1 is num3 - 1. Since each value of num2 is added to num1, the code segment computes the sum of the integers from num2 to num3 - 1.
Q#: 38
- The correct answer should be D because the option I is correct. The code segment uses a for loop to traverse the valueList array. The statement inside the loop calls the get method to access a Value object and then calls the getNum method to access the num instance variable. Option II is correct. The code segment uses an enhanced for loop to traverse the valueList array.
Q#: 39
- The correct answer should be D because if the first character of str is lexicographically greater than the second character of str, the method returns the result of the recursive call with a parameter that contains all but the first character of str. If the first character of str is lexicographically less than or equal to the second character of str, the method returns false.
Q#: 40
- The correct answer should be A because at compile time, methods in or inherited by the declared type determine the correctness of a non-static method call. In line 1, obj1 is declared as an object of type A. Therefore, at compile time, there must be a message method in class A or its superclass. If the message method in class A is removed, the statement in line 3 will no longer compile.
Self-Reflection:
-
When I was working through these corrections, it helped me realize how important it is to pay close attention to details in Java code, especially with logic flow, recursion, and how loops behave.
-
I noticed that I usually made mistakes with things like method overriding, constructor signatures, and recursive logic.
-
Reviewing the correct answers and explanations gave me a better understanding of how Java handles class inheritance, conditionals, and array traversals.