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.

💻 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:

Example 1: Static Methods
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);
    }
}
Running…

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:

Example 2: Instance Methods Require an Object
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
    }
}
Running…

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:

Example 3: Method Chaining and NPE Trap
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);
    }
}
Running…

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.

1
⚠ Calling an instance method without an object

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
2
⚠ Calling a static method on an instance variable

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
3
⚠ Forgetting that instance methods can return new objects

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
4
⚠ Calling any method on null

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
🎓 AP Exam Tip

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.

⚠ Watch Out!

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)

Your Score: 0 / 0
1. Which of the following is a static method call?
2. What is required before calling an instance method?
3. What is wrong with: String.toUpperCase()?
4. What is printed?
String s = "hello";
s.toUpperCase();
System.out.println(s);
5. Which call would throw a NullPointerException?
6. What does method chaining mean?
7. Which is the correct way to call Math.abs in Java?
8. How many objects must exist to call an instance method?

❓ Frequently Asked Questions

What is the difference between a static and instance method in AP CSA?

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.

How do I know if a method is static or instance?

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.

What is method chaining?

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'.

Why does calling a method on null throw NullPointerException?

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.

Can I call a static method on an instance variable?

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.

TC

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

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]