AP CSA Unit-Level MCQ
Code Tracing: Object State and Encapsulation
Practice mode with 50 Java-focused questions, immediate answer checks, and explanations.
For practice use only.
Code Tracing: Object State and Encapsulation MCQ Practice
Code Tracing: Object State and Encapsulation AP Computer Science A topic practice with 50 original Java MCQs and immediate explanations.
Question 1 of 50
Answered 0 of 50
Choose one answer.
What is printed by this Object State and Encapsulation code trace?
public class Main {
public static void main(String[] args) {
Tracker t = new Tracker(18);
t.add(3);
t.add(5);
System.out.print(t.getValue());
}
}
class Tracker {
private int value;
public Tracker(int start) { value = start; }
public void add(int amount) { value += amount; }
public int getValue() { return value; }
}