πŸ“š

Β >Β 

πŸ’»Β 

Β >Β 

βš™οΈ

5.12 MC Answers and Review

6 min readβ€’december 22, 2021


AP Computer Science AΒ πŸ’»

130Β resources
See Units

Answers and Review for Multiple Choice Practice on Writing ClassesΒ 

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-o7tHnqsXEVgn.png?alt=media&token=f4f831bc-6e3c-42f2-82ba-c3357f1fb09e

Image From Wikipedia.

Β 
β›”STOP!β›” Before you look at the answers make sure you gave this practice quiz a try so you can assess your understanding of the concepts covered in unit #. Click here for the practice questions: AP Name Unit 5 Multiple Choice Questions.
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)
Answer:Β public=modifier int=return type getX = name of the method
πŸ“„ Study AP CSA, Unit 5.1: Anatomy of a Class

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.
Answer:Β result will always be 0
πŸ“„Β Study AP CSA, Unit 5.4:Β Accessor Methods

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;
Answer:Β random is in the Math library.. values can be 0-1, multiplied by 36 gives values between 0 & 35.999. adding 25 gives 25-60
πŸ“„Β Study AP CSA, Unit 5.6:Β Writing Methods

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.
Answer:Β && is AND ! is NOT || is OR
πŸ“„Β Study AP CSA, Unit 5.6:Β Writing Methods

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).
Answer:Β exclued the case where i could be = to animals.length
πŸ“„Β Study AP CSA, Unit 5.6:Β Writing Methods

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
Answer:Β definitely not III. II works (and is in every choice). Although I is close, it won't work
πŸ“„Β Study AP CSA, Unit 5.6:Β Writing Methods

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"]
Answer:Β "one" and "two" are replaced with "three" and "four" and then "five" added after
πŸ“„Β Study AP CSA, Unit 5.6:Β Writing Methods

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
Answer:Β The code skips some of the elements because some of the indexes change by one when an element is removed
πŸ“„Β Study AP CSA, Unit 5.6:Β Writing Methods

9. For the following class definitions & the code segment below, what will be printed upon execution?

A. 6
B. 68
C. 124
D. 1212
Answer:Β the code segment is not in the class Thing1 or Thing2
πŸ“„Β Study AP CSA, Unit 5.6:Β Writing Methods

10. What is a class used to define?

A. a method
B. a variable
C. a static parameter
D. a return value
Answer:Β definition of a class
πŸ“„Β Study AP CSA, Unit 5.1:Β Anatomy of a ClassΒ 

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
Answer:Β definition of a constructor, also used to initialize fields in a new object
πŸ“„Β Study AP CSA, Unit 5.2:Β ConstructorsΒ 

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
Answer:Β definition of an object in an OOP
πŸ“„Β Study AP CSA, Unit 5.2:Β Constructors

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");
Answer:Β A static method must be called by the class & has the form: className.methodName(parameters)
πŸ“„Β Study AP CSA, Unit 5.7:Β Static Variables and Methods

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
Answer:Β a mutator is also known as a setter
πŸ“„Β Study AP CSA, Unit 5.5:Β Mutator Methods

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
Answer:Β definition of a mutator method
πŸ“„Β Study AP CSA, Unit 5.5:Β Mutator Methods

What can we help you do now?

πŸ” Study for Unit 6
🦘 Jump to AP CSA Unit 6 Multiple Choice Questions
🀝 Connect with other students studying AP CSA with Hours
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