AP CSA Unit 3 Day 3: Accessor Method Side Effects

Unit 3, Classes & Objects • Cycle 2
Day 3 Advanced Practice • Harder Difficulty
Focus: Accessor Method Side Effects Hard Accessor Method Side Effects

Advanced Practice Question

Format: Accessor Method Side Effects

Which statement is TRUE about this accessor method?
public class Data {
    private int[] nums;
    
    public int[] getNums() {
        return nums;
    }
}
Difficulty: Hard  |  Topic: Accessor Method Side Effects  |  Cycle: 2 (Advanced)
Why This Answer?

Returning a direct reference to a private array allows external code to modify the array contents, breaking encapsulation. Should return nums.clone() or a copy.

Common Mistake
Watch Out!

Thinking that returning a private variable is always safe for accessors.

AP Exam Strategy

Arrays and objects are references—return a COPY to preserve encapsulation.

Master This Topic

This Cycle 2 HARD question tests accessor method side effects. Review Unit 3 concepts to build mastery of classes & objects.

  • Understanding accessor method side effects
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 3 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.