AP Computer Science A Practice Quiz: Anatomy of a Class
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 9 questions to check your progress.
Question 1 of 9
All Questions (9)
A) It allows access from any class in the same project.
B) It restricts access to the declaring class only.
C) It makes the member accessible only to subclasses.
D) It allows access from classes outside the declaring class.
Correct Answer: B
The provided content explicitly states, 'The keyword private restricts access to the declaring class...'
A) A technique to make all class data public for easy access.
B) A technique where the implementation details of a class are kept hidden from external classes.
C) A method for ensuring that a class can have multiple constructors.
D) The process of naming a class and its methods clearly.
Correct Answer: B
The content defines data encapsulation as 'a technique in which the implementation details of a class are kept hidden from external classes.'
A) As `public`, to allow direct manipulation from other classes.
B) As `private`, unless the class specification states otherwise.
C) Without any access modifier, to use the default visibility.
D) As `public` for data and `private` for methods.
Correct Answer: B
The content states, '...it is good programming practice to designate the instance variables for these attributes as private unless the class specification states otherwise.'
A) private
B) internal
C) public
D) hidden
Correct Answer: C
The content specifies that 'the keyword public allows access from classes outside the declaring class,' which is necessary for the `Driver` class to access a method in the `Car` class.
A) To improve the compilation speed of the program.
B) To allow any external class to modify the attributes directly.
C) To accomplish data encapsulation.
D) To reduce the number of methods required in the class.
Correct Answer: C
The provided text directly states, 'Access to attributes should be kept internal to the class in order to accomplish encapsulation.'
A) public int pageCount;
B) private int pageCount;
C) public Book(int pageCount) {}
D) private void setPageCount() {}
Correct Answer: B
To achieve data encapsulation, the content advises that instance variables (attributes) should be designated as `private`. This hides the implementation detail (`pageCount`) from external classes.
A) A class with public instance variables and private methods.
B) A class with private instance variables and public methods to access and modify that data.
C) A class where all variables, constructors, and methods are declared public.
D) A class where all variables, constructors, and methods are declared private.
Correct Answer: B
This choice aligns with the principles of making instance variables `private` to hide them (encapsulation) and providing `public` methods to allow controlled access from outside the class.
A) Their memory allocation.
B) Their performance and speed.
C) Their access and visibility.
D) Their data type.
Correct Answer: C
The first point of the content is to 'Develop code to designate access and visibility constraints to classes, data, constructors, and methods.' The keywords `private` and `public` are the tools for this.
A) Because it forces all data to be constant and unchangeable.
B) Because it allows any part of the program to inspect the variables for debugging.
C) Because it prevents external classes from directly accessing and modifying the internal state of an object, which is the definition of hiding implementation details.
D) Because it makes the code shorter and easier to write.
Correct Answer: C
Data encapsulation is about hiding implementation details. By making instance variables `private`, you restrict access to them, forcing external classes to use public methods (if provided). This hides the internal state and is the core mechanism for encapsulation as described in the text.