AP CSA Unit 3.7: Static Methods Practice
Share
Unit 3, Section 3.7
Day 7 Practice • January 13, 2026
🎯 Focus: Static Methods
Practice Question
Consider the following class:
public class MathHelper {
public static int square(int n) {
return n * n;
}
public static int sumOfSquares(int a, int b) {
return square(a) + square(b);
}
}
// Client code:
System.out.println(MathHelper.sumOfSquares(3, 4));
What is printed as a result of executing the client code?
What This Tests: Section 3.7 covers static methods. Static methods belong to the class itself, not to any object. Call them with ClassName.methodName()—no object needed!
Step-by-Step Trace
MathHelper.sumOfSquares(3, 4)
= square(3) + square(4)
= 9 + 16
= 25
| Step | Call | Calculation | Returns |
|---|---|---|---|
| 1 | sumOfSquares(3, 4) | square(3) + square(4) | ? |
| 2 | square(3) | 3 * 3 | 9 |
| 3 | square(4) | 4 * 4 | 16 |
| 4 | sumOfSquares returns | 9 + 16 | 25 |
Static vs Instance Methods
// STATIC: called on the CLASS
MathHelper.square(5); // No object needed
Math.abs(-7); // Math class example
// INSTANCE: called on an OBJECT
String s = "hello";
s.length(); // Needs an object
Common Mistakes
Mistake: Answer A (7)
This adds 3 + 4 = 7 without squaring. The method squares each number THEN adds: 9 + 16 = 25.
Mistake: Answer E (Error)
Static methods DON'T need an object! That's the whole point—they belong to the class, so ClassName.method() works fine.
When to Use Static
Static Method Guidelines
Use static when the method:
- Doesn't need any instance variables
- Performs a utility calculation (like Math methods)
- Should be callable without creating an object
Examples: Math.abs(), Math.pow(), Integer.parseInt()
Difficulty: Medium • Time: 2-3 minutes • AP Skill: 3.A - Call methods
Completed Unit 3 Week 1! 🎉
Great job finishing all 7 days of class creation!
Premium Question Bank - Coming Soon Schedule 1-on-1 Tutoring