2020 AP Practice Test
##MC
Score 17/40 (30 attempted)
Question 6
- I. turns 2 into a double and the rest of the operations into a double
- II. Solve 2/4 first then turns 0 into a double
- III. Solves the operations in () and then turns answer into a double
Question 8
- n1 and n2 only exits in the Points
- Have to use num1 and num2 since they are global variables
- Double values can be set equals to the integer values.
Question 9
- add() with array list will inset the value in the index.
- Everything after will be moved down.
- set() replaces the number in the specified index.
Question 11
- A. will print 10 and then subtract num
- In C. num is set to 10 and then is subtracted before printing
- 9 will be printed first, all the way to 1.
Question 12
- getName() function does not exist.
- Borrower is a variable which can be compared.
- Can directly compare to null.
Question 17
- Since j is initialized as a SuperHero object, the j.powerUp(10) method accessed is from the subclass.
- Subclass method uses super keyword with the parameter 20.
- Subclass adds p to original power value (50 + 2*10).
Question 19
- Nested for loop
- First element in each row is multiplied by two
- Sum of all the elements
- Keep track of variables when debugging
Question 20
- Nested for loop goes through each book in array
- getpages() used to get number of pages for each book
- Compare it to max page value and switch if condition is met
Question 23
- Nested for each loop goes through every element in double array.
- When using nested for loop, don’t need to use index number
- nested for loop references the element itself.
Question 24
- y is a static variable, it is linked with everything in the class
- When y is called, it increases by one
- Going through the methods, the y value ends up to be 14.
Question 31
- I. works because while loop goes through every i value and checks the condition correctly.
- II. does not work because it does not check the first value in the array.
- III. does not work because for each loop goes through every number and num index. Using i as the index will return wrong values.
Question 33
- Debug through writing the variables of the loop down.
- Row increases by one before going to the next line.
- F and j are part of the first column, so they will be printed on the top.
Question 34
- As element of the array list get removed, the index of these values changes.
- Since i is always increasing by one, some elements are skipped.
- Can fix this code by checking array list backwards.
Question 35
- Check if the values are equal.
- Increase the counter if condition is met
- If the counter is bigger than the previous stored mode value, change it.
Question 36
- When a and b are both odd
- 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.
Question 39
- 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.
- If no such character pair is found, the base case is reached and the value true is returned.
Question 40
- At compile time, methods in or inherited by the declared type determine the correctness of a non-static method call.
- 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.