Side effect in AP Computer Science A

In AP Computer Science A, a side effect is any action a method performs beyond returning a value, such as printing output or modifying an object's instance variables. Void methods exist entirely for their side effects, since they return nothing at all.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is side effect?

A side effect is anything a method does that you can't see in its return value. The two big ones in AP CSA are printing to the console (like System.out.println) and changing state (like updating an instance variable). Think of a method's return value as its official answer and side effects as everything else it does while it's working.

This idea sits at the heart of Topic 3.5 (Writing Methods). The CED splits methods into two camps. A non-void method returns a single value using return by value (EK 3.5.A.2, EK 3.5.A.3). A void method returns nothing (EK 3.5.A.1), which means the only reason a void method exists is its side effects. If a void method had no side effects, it would do literally nothing. One more wrinkle from EK 3.5.A.4 matters here. The return keyword sends control back to the caller, so any side effect written after a return statement never happens.

Why side effect matters in AP® Computer Science A

Side effects live in Unit 3 (Class Creation), Topic 3.5, supporting learning objective 3.5.A: develop code to define behaviors of an object through methods and determine the result of calling these methods. "Determine the result" is the key phrase. The result of a method call isn't just its return value. It's also every print statement that ran and every instance variable that changed. If you only track return values when tracing code, you'll miss half of what the question is asking about. Understanding side effects is also how you decide what kind of method to write on FRQs. If the task says "update" or "print," you probably want a void method built around side effects. If it says "return" or "calculate," you want a return value.

How side effect connects across the course

Void Methods (Unit 3)

A void method returns no value (EK 3.5.A.1), so side effects are its entire job. When you see void in a method header, ask yourself what this method prints or changes, because that's the only way it has any effect.

Return by Value (Unit 3)

Return by value (EK 3.5.A.3) is the opposite channel of communication. A returned value goes back to the caller to be used in an expression, while a side effect changes the world directly. A single non-void method can do both, returning a value and changing state along the way.

Early Return (Unit 3)

EK 3.5.A.4 says code after a return statement never executes. So if a method hits an early return, any side effects written below that point are skipped. Tracing questions love to hide a print statement after a return to see if you notice it's unreachable.

Is side effect on the AP® Computer Science A exam?

No released FRQ uses the phrase "side effect" verbatim, but the concept is baked into both sections of the exam. Multiple-choice questions give you a method and ask what gets printed or what an instance variable equals after the call. That's asking you to trace side effects, not just return values. On the free-response class-writing questions, the prompt tells you implicitly which kind of method to write. "Returns the total" means a non-void method with a return value. "Updates the score" or "prints each element" means a void method whose whole purpose is its side effect. Mixing these up, like printing a value when the rubric wants it returned, costs points even when your logic is correct.

Side effect vs Return value

A return value is data handed back to the caller, where it can be stored in a variable or used in an expression. A side effect happens immediately and changes something outside the method, like the console output or an object's state. Printing a number is NOT the same as returning it. System.out.println(sum) shows the value on screen but gives the caller nothing to work with, while return sum; hands the value back silently. This is one of the most common ways to lose FRQ points.

Key things to remember about side effect

  • A side effect is anything a method does besides returning a value, most commonly printing output or modifying instance variables.

  • Void methods (EK 3.5.A.1) return nothing, so they are useful only because of their side effects.

  • Printing a value and returning a value are completely different. Printing shows the value to the user, while returning hands it back to the calling code.

  • Code after a return statement never runs (EK 3.5.A.4), so side effects placed after a return are unreachable.

  • When tracing code on the exam, track both the return value and every side effect, because LO 3.5.A asks you to determine the full result of calling a method.

Frequently asked questions about side effect

What is a side effect in AP Computer Science A?

A side effect is any action a method performs other than returning a value, like printing with System.out.println or changing an instance variable. It's covered in Topic 3.5 (Writing Methods) in Unit 3.

Is printing a value the same as returning it?

No. Printing is a side effect that displays the value on the console, while returning sends the value back to the caller so it can be stored or used in an expression. Writing System.out.println(answer) when the FRQ asks you to return answer is a classic point-loser.

How is a side effect different from a return value?

A return value is the single piece of data a non-void method hands back via the return keyword (EK 3.5.A.2). A side effect is everything else the method does, like console output or state changes, and it happens whether or not anything is returned.

Can a non-void method have side effects too?

Yes. A method can return a value and also print or modify instance variables in the same call. Void methods are the ones limited to side effects only, since they have no return value.

Do side effects run if they come after a return statement?

No. EK 3.5.A.4 says the return keyword sends control back to the caller, so any print statement or variable update written after a return is never executed. Exam tracing questions test this with early returns inside if statements.