AP CSA Calling Methods
Calling Methods in AP CSA: Static vs Instance Complete Guide (2025-2026)
Calling methods in AP CSA requires understanding the critical distinction between static (class) methods called as ClassName.method() and instance methods called as objectReference.method(). This distinction appears throughout Unit 1 (15–25%) and is tested in both MCQ and FRQ sections. Math.random() and Integer.parseInt() are static — they belong to the class. s.length() and list.size() are instance — they belong to a specific object. Calling a static method on an instance (or vice versa) is one of the most common AP compile-error traps.
📄 Table of Contents
💻 Code Examples — Predict First
Before running each example, write down your prediction. This is the single most effective AP exam study technique.
🤔 Predict the output before running:
public class Main {
// Static method: belongs to the class
public static int doubleIt(int n) {
return n * 2;
}
public static void main(String[] args) {
// Static: called on class name (or directly in same class)
System.out.println(Math.abs(-5)); // Math.abs is static
System.out.println(Math.random()); // static
int result = doubleIt(7); // static in same class
System.out.println(result);
}
}
5 / (random double) / 14 — Math.abs() and Math.random() are static: called on the class name. doubleIt() is static in the same class so it can be called without a class prefix.
🤔 Predict the output before running:
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
// Instance methods: need an object first
String s = "hello"; // create object
System.out.println(s.length()); // instance method
System.out.println(s.toUpperCase());
ArrayList list = new ArrayList<>();
list.add(42);
System.out.println(list.size()); // instance method
}
}
5 / HELLO / 1 — s.length() and list.size() are instance methods: they need a specific object (s, list) to operate on. You cannot call String.length() without a String object.
🤔 Predict the output before running:
public class Main {
public static void main(String[] args) {
// Method chaining: each method returns an object
String result = " hello world "
.trim()
.toUpperCase()
.substring(0, 5);
System.out.println(result);
// Calling instance method on null -> NPE
String s = null;
// s.length(); // NullPointerException!
System.out.println(s == null);
}
}
HELLO / true — Method chaining works because each method returns a new String object. The .trim() result has .toUpperCase() called on it, etc. Calling any instance method on null causes NullPointerException.
❌ Common Pitfalls
These are the mistakes students most often make on the AP CSA exam with calling methods AP CSA static instance. Study them carefully.
Instance methods must be called on an object reference: s.length() not String.length(). Calling without an object is a compile error. The object before the dot IS the data the method operates on.
String.length() // COMPILE ERROR: no object s.length() // CORRECT: s is the String object
Static methods can be called on a class name. While Java technically allows obj.staticMethod(), it is misleading and the AP exam treats it as bad practice. Always call static methods on the class: Math.abs() not someDouble.abs().
Math.abs(-5) // CORRECT: static on class // avoid calling static methods on instances
Methods like s.toUpperCase() return a new String object. You can immediately call another method on the returned object — this is method chaining. Students often assign to a variable when chaining would be cleaner.
"hello".toUpperCase().substring(0,3) // "HEL" via chaining
If a variable holds null, calling any instance method on it throws a NullPointerException at runtime. Always verify a reference is non-null before calling methods on it.
String s = null; s.length(); // NullPointerException at runtime
On the AP exam, the quickest way to classify a method call: if it uses a CLASS name before the dot (Math.sqrt, Integer.parseInt), it’s static. If it uses an OBJECT VARIABLE before the dot (s.length(), list.add()), it’s an instance method.
The most tested static methods on the AP exam: Math.random(), Math.abs(), Math.pow(), Math.sqrt(). The most tested instance methods: String.length(), String.substring(), String.equals(), ArrayList.add(), ArrayList.get(), ArrayList.size().
✍ Check for Understanding (8 Questions)
String.toUpperCase()?
String s = "hello";
s.toUpperCase();
System.out.println(s);
❓ Frequently Asked Questions
A static method belongs to the class and is called with ClassName.method(). It does not operate on a specific object. An instance method belongs to an object and is called with objectRef.method(). It operates on the specific object's data.
Static methods are called on a class name (Math.sqrt, Integer.parseInt). Instance methods are called on an object variable (s.length(), list.add()). If the method appears in the AP Quick Reference under a class with no 'new' required, it's static.
Method chaining calls a method on the object returned by a previous method. For example, 'hello'.toUpperCase().substring(0,3) calls toUpperCase() on the String, which returns a new String 'HELLO', then calls substring(0,3) on that result to get 'HEL'.
null means 'no object'. Instance methods need an actual object to operate on. When you call s.length() and s is null, there is no String object for length() to work on, so Java throws NullPointerException at runtime.
Technically Java allows it, but it is misleading and considered bad practice. Math.abs(-5) is correct. Calling abs on a variable is confusing and the AP exam expects you to use the class name for static methods.
Tanner Crow — AP CS Teacher & Tutor
11+ years teaching AP Computer Science at Blue Valley North High School (Overland Park, KS). Verified Wyzant tutor with 1,845+ hours, 451+ five-star reviews, and a 5.0 rating. His AP CSA students score 5s at more than double the national rate.
- 54.5% of students score 5 on AP CSA (national avg: 25.5%)
- 1,845+ verified tutoring hours • 5.0 rating
- Free 1-on-1 tutoring inquiry: Wyzant Profile
🔗 Related Topics
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]