πŸ“š

Β >Β 

πŸ’»Β 

Β >Β 

βš™οΈ

5.11 Multiple Choice Questions

5 min readβ€’december 22, 2021


AP Computer Science AΒ πŸ’»

130Β resources
See Units

Multiple Choice Practice for Writing Classes

Welcome to Unit 5 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 5 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 5 Here:Β Intro to Unit 5
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-oZ5JVklkULCN.png?alt=media&token=7ed66be9-22db-4863-818e-fb274d48bea6

Image 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. Which of the following is a correct header for a method of the Example class that would return the value of the private instance variable x so that it can be used in a class other than Example?
A. private int getX()
B. public int getX()
C. private void getX()
D. public void getX(int x)

2. Consider the processWords method. Assume that each of its two parameters is a String of length two or more. Which of the following best describes the value printed when processWords is called?
A. The value result.length() - 1 is printed.
B. The value 1 is always printed
C. The value 0 is always printed
D. A substring containing the last character of word2 is printed.

3. Which of the following statements assigns a random integer between 25 and 60, inclusive, to rn?
A. int rn = (int) (Math.random() * 25) + 60;
B. int rn = (int) (Math.random() * 26) + 60;
C. int rn = (int) (Math.random() * 25) + 36;
D. int rn = (int) (Math.random() * 36) + 25;

4. Which of the following best describes the value of the Boolean expression a && !(b || a)
A. The value is always true
B. The value is always false
C. The value is true when a has the value false, and is false otherwise
D. The value is true when either a or b has the value true, and is false otherwise.

5. In the following code segment, the string str has been declared and initialized. The code segment is intended to print the number of strings in the array animals that have str as a substring. Which of the following changes should be made so the code segment works
as intended?
A. The Boolean expression in the for loop header should be changed to i < animals.length
B. The Boolean expression in the for loop header should be changed to i < animals.length -1.
C. The Boolean expression in the for loop header should be changed to i < animals[i].length
D. The condition in the if statement should be changed to animals[i].equals(str).

6. Consider an integer array, nums, which has been declared and initialized with one or more integer values. Which of the following code segments updates nums so that each element contains the square of its original value?
A. II only
B. I and II only
C. II and III only
D. I, II, and III

7. Which of the following represents the contents of numbers after the code segment has been executed?
A. ["one", "four", "five"]
B. ["three", "four", "two"]
C. ["three", "two", "five"]
D. ["three", "four", "five"]

8. Consider the following method, which should return a list containing the elements of the parameter myList with all elements removed. Which of the following best explains why the code doesn't work as
intended?
A. The code segment causes an IndexOutOfBoundsException for all lists because of an incorrect Boolean expression in the for loop
B. The code segment skips some elements of myList because the indexes of all subsequent elements change by one when a list element is removed.
C. The code segment causes an IndexOutOfBoundsException for lists with at least one even element because the indexes of all subsequent elements change by one when a list element is removed.
D. The code segment removes the wrong elements of myList because the condition in the if statement to test whether an element is even is incorrect

9. For the following class definitions & the ocde segment below, what will be printed upon execution?
A. 6
B. 68
C. 124
D. 1212

10. What is a class used to define?
A. a method
B. a variable
C. a static parameter
D. a return value

11. Which of the following is the best definition of a constructor?
A. a way to initialize a mutator
B. a way to initialize a list
C. a way to initialize a method
D. a way to initialize a field

12. In Java, what is an object?
A. An object is one element in a constructor method
B. An object names a variable that can change in a program
C. An object does the actual work in an object-oriented program
D. An object is a static variable in a program

13. Which of the following is a correct call to a static method?
A. name.substring(7);
B. Math.pow (3,6);
C. circle.getDiameter();
D. student.setEmail("smith@student.dist221.org");

14. The following code is an example of ______?
A. general code for a mutator
B. general code for a getter
C. general code for an accessor
D. general code for a static method

15. Which of the following is a decent definition for a mutator method?
A. A mutator method is accessible outside of the class
B. A mutator method is often a static method
C. A mutator method often sets the instance variable to a value in its parameter
D. A mutator method is also a getter for the method

Time to Check Your Answers on Unit 5 Practice Questions Answers and Review! πŸ™Œ
Browse Study Guides By Unit
βž•Unit 1 – Primitive Types
πŸ“±Unit 2 – Using Objects
πŸ–₯Unit 3 – Boolean Expressions & if Statements
πŸ•ΉUnit 4 – Iteration
⌚️Unit 6 – Array
πŸ’ΎUnit 7 – ArrayList
πŸ’»Unit 8 – 2D Array
πŸ–²Unit 9 – Inheritance
πŸ–±Unit 10 – Recursion
πŸ™Exam Reviews