Welcome to Unit 6 AP Computer Science A Multiple Choice Questions! Grab some paper and a pencil π to record your answers as you go. You can see how you did on the
Unit 6 Practice Questions Answers and Review sheet once you're done. Don't worry, we have tons of resources available if you get stumped π on a question. And if solo study is not your thing, join a group in
Hours!
Not ready to take a quiz yet?
Start studying unit 6 Here: Intro to Unit 6Image From Wikipedia.
Facts about the test: The AP Computer Science A exam has 40 multiple choice questions and you will be given 90 minutes to complete the section. That means it should take you around 34 minutes to complete 15 questions.
*The following questions were not written by CollegeBoard and although they cover information outlined in the AP Computer Science A Course and Exam Description the formatting on the exam may be different.
1. Given the code segment: int[] arr = {1, 2, 3, 4, 5}; which of the following would set the first two elements of array arr to 10, making the new value of array arr {10, 10, 3, 4, 5} ?
A. arr [0, 1] = 10
B. arr[1] = 10; arr [2] = 10;
C. arr = 10, 10, 3, 4, 5
D. arr[0] = 10; arr [1] = 10;
2. Given the method (below), with the code segment (below) that appears in a method in the same class as transform.
/ missing code /
arr = transform(arr);
After running the code segment, the array should be {1, 0, 1, 0}. Which of the following can replace / missing code / so that it works as intended?
A. I and III
B. I and II
C. III only
D. I only
3. If you have a program that reads the lines of a text file into a sequential list of lines, which of the following is a good reason to implement the list with an ArrayList of String objects rather than an array of String objects?
A. The String methods are easier to use with an ArrayList than with an array.
B. The get and set methods of the ArrayList are more convenient than the [] notation for arrays.
C. The size method of ArrayList gives instant access to the length of the list.
D. If any text file is long, ArrayList will automatically be resized. The array, though, may go out of bounds.
4. Consider writing a program that produces statistics for long lists of numerical data. Which of the following is the best reason to implement each list with an array, rather than an ArrayList of Integer (or Double) objects?
A. Removal of elements from a list is easier to code for an array than for an ArrayList.
B. Insertion of new elements into a list is easier to code for an array than for an ArrayList.
C. An array of primitive data is more efficient to manipulate than an ArrayList of wrapper objects that contain numbers.
D. Accessing individual elements in the middle of a list is easier for an array than for an ArrayList.
5. Which of the following for loops will give the same output as the code segment?Β
A.
B.
C.
D.
6. Consider the class: (below). A program that simulates a bingo card declares an array of BingoCard. The array has NUMPLAYERS elements, where each element represents the card of a different player. Here is a code segment that creates all the bingo cards in the game (below): Which of the following is a correct replacement for
/ declare array of BingoCard /?
A. BingoCard[] players = new BingoCard[NUMPLAYERS];
B. int[] BingoCard = new BingoCard[NUMPLAYERS];
C. BingoCard[] players = new int[NUMPLAYERS];
D. int[] players = new BingoCard[NUMPLAYERS];
7. Which of the following best shows the contents of the array after the code runs?
A. {10, 20, 50, 90, 50}
B. {10, 20, 50, 90, 140}
C. {10, 30, 60, 100, 150}
D. {10, 20, 30, 70, 120}
8. What is a data structure used to implement a list object, where elements in the list are of the same type
A. object
B. static
C. method
D. array
9. Can statements following an array's initialization reassign data to a new array of a specified length?
A. only for integer arrays
B. sometimes
C. no
D. yes
10. When arrays are declared, what are the elements initialized for automatically (default values)?
A. primitives: 1, boolean: true, objects: null
B. primitives: 1, boolean: false, objects: null
C. primitives: 0, boolean: false, objects: null
D. primitives: 0, boolean: true, objects: null
11. Fibonacci numbers form a pattern starting with 1, 1.... after this, each next number is the sum of the previous 2: 1, 1, 2, 3, 5, 8, and 13. the given code (below) is meant to fill the fibs array with the first ten Fibonacci numbers but is not working correctly. Which of the following best explains why the code isn't working correctly?
A. In the for loop header, the initial value of j should be 0.
B. In the for loop header, the initial value of j should be 2.
C. The for loop condition should be j < fibs.length - 1.
D. The for loop should increment j by 2 instead of by 1.
12. Which of the following is used for accessing the index of any element, removing / replacing elements, or when just want to access SOME of the elements
A. for loop
B. while loop
C. if loop
D. do while loop
13. Which of the following will be the result of running the given code (below)?
A. A run-time error will result
B. an infinite loop will result
C. Sum of arr [1], arr[2],..., arr [arr.length-1] will be stored in sum
D. Sum of arr [0], arr[1],..., arr [arr.length] will be stored in sum
14. How are primitive types passed?
A. by object
B. by method
C. by reference
D. by value
15. Which of the following is NOT an advantage of ArrayLists over arrays?
A. ArrayLists can shrink & grow while arrays have fixed lengths
B. an ArrayList's last slot is always list.size() while for a partially filled array you must keep track of the last slot
C. arrays can shrink & grow while ArrayLists have fixed lengths
D. in an ArrayList, System.out.print(list) outputs the element, while in an array you must write code to override toString() or else the output is a hashcode
Time to Check Your Answers onΒ Unit 6 Practice Questions Answers and Review! π