AP Computer Science A Practice Quiz: Class Variables and Methods
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 13 questions to check your progress.
Question 1 of 13
All Questions (13)
A) final
B) class
C) static
D) shared
Correct Answer: C
The provided content states, 'Class variables are designated with the static keyword before the variable type.'
A) Each object gets its own independent copy of the variable.
B) All objects share a single copy of the variable.
C) Only the first object created can access the variable.
D) The variable is re-initialized for each new object.
Correct Answer: B
The content explicitly says, 'all objects of a class sharing a single copy of the class variable.'
A) To initialize the instance variables of a specific object.
B) To define behaviors that belong to the class as a whole.
C) To create new instances (objects) of the class.
D) To access and modify only the instance variables of an object.
Correct Answer: B
The first point in the content is to 'Develop code to define behaviors of a class through class methods.' This indicates they relate to the class as a whole, not individual objects.
A) They can only access instance variables that are declared `public`.
B) They cannot access or change instance variables at all.
C) They can only access class variables, not instance variables.
D) They cannot access instance variables directly without being passed an object reference.
Correct Answer: D
The content states, 'Class methods cannot access or change the values of instance variables... without being passed an instance of the class via a parameter.'
A) Line 1
B) Line 2
C) Line 3
D) Line 4
Correct Answer: B
Line 2 correctly declares a class variable because it uses the `static` keyword. This variable will be shared across all `Book` objects.
A) 0
B) 100
C) It will be uninitialized.
D) It will cause a compilation error.
Correct Answer: B
Because `highscore` is a static (class) variable, all objects of the `Game` class share a single copy. When `game1` changes its value to 100, that single copy is updated. `game2` will therefore access the same variable with the value of 100.
A) position = targetPosition;
B) this.position = targetPosition;
C) r.position = targetPosition;
D) Robot.position = targetPosition;
Correct Answer: C
Class methods cannot access instance variables like `position` directly. However, they can access them through an instance of the class passed as a parameter. In this case, `r` is an instance of `Robot`, so `r.position` is a valid way to access its instance variable.
A) Line A
B) Line B
C) Line C
D) Line D
Correct Answer: D
The `printInfo` method is a class method (static). It cannot directly access the instance variable `instanceCount`. Accessing the class variable `totalCount` (Line C) is allowed.
A) Class variables are `private`, while instance variables are `public`.
B) A single copy of a class variable is shared by all objects, while each object has its own copy of an instance variable.
C) Class variables can only be integers, while instance variables can be any type.
D) Class variables are declared inside methods, while instance variables are declared at the class level.
Correct Answer: B
The content states that 'all objects of a class sharing a single copy of the class variable,' which contrasts with instance variables, where each object has its own unique set.
A) It is impossible for a class method to change an object's state.
B) By using the `this` keyword to refer to the object.
C) By passing the specific object to the method as a parameter.
D) By declaring the method with the `void` return type.
Correct Answer: C
The text explicitly mentions that class methods can access or change instance variables if they are 'passed an instance of the class via a parameter.'
A) To the specific object that created it.
B) To the method in which it is declared.
C) To the class itself.
D) To the constructor of the class.
Correct Answer: C
The provided content clearly states, 'Class variables belong to the class...'
A) 0
B) 1
C) 2
D) The code will not compile.
Correct Answer: C
The `itemCount` is a static (class) variable, so there is only one copy. The `Item` constructor is called twice, once for `item1` and once for `item2`. Each call increments the single `itemCount` variable. It starts at 0, is incremented to 1, then incremented to 2. The final value printed is 2.
A) An instance method of the same class.
B) Another class method of the same class.
C) The constructor of the class.
D) An instance method of another class.
Correct Answer: B
The content states that class methods cannot call instance methods without an object reference. By extension, they can directly call other class (static) methods because those methods also belong to the class itself and do not depend on a specific object's state.