Return Statement

In AP Computer Science A, a return statement immediately ends a method's execution and sends a value back to the line of code that called it; the value's type must match the return type declared in the method header, and void methods return no value at all.

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

What is Return Statement?

A return statement does two jobs at once. First, it hands a value back to whoever called the method. Second, it immediately stops the method, even if there's more code below it. When Java hits return, control jumps straight back to the call site, and the method call expression gets replaced by the returned value. So if getBalance() returns 250.0, the call double b = account.getBalance(); behaves as if you wrote double b = 250.0;.

The value you return has to match the return type in the method header. A method declared public int countDown(int n) must return an int on every possible path through the method. If the header says void, the method returns nothing, and you can still write a bare return; to exit early. Think of a non-void method as a vending machine. You call it, it does its work, and it must hand something back. A void method is more like flipping a light switch. It does something, but nothing comes back to you.

Why Return Statement matters in AP Computer Science A

Return statements thread through almost the entire AP CSA course. You start using them in Unit 2 when you call non-void methods on objects and have to do something with the result (store it, print it, or use it in an expression). In Unit 5 you flip to the other side and write your own methods, where every non-void method you write on an FRQ needs a correct return statement or you lose points. By Unit 10, return statements are the engine of recursion, because each recursive call returns a value that the previous call uses to build its own answer. The exam constantly tests whether you can trace what a method call evaluates to, and that's entirely a question about what gets returned.

How Return Statement connects across the course

Method header and return type (Units 2 & 5)

The method header is a promise and the return statement keeps it. If the header declares public int getCount(), every path through the method must return an int. Mismatching the declared return type and the returned value is a compile-time error the MCQ section loves to test.

Void methods (Unit 5)

Void is the opposite case. A void method produces an effect (like printing or changing an instance variable) but returns no value, so writing int x = someVoidMethod(); won't compile. You can still use a plain return; inside a void method to bail out early.

Recursion (Unit 10)

Recursive methods are basically return statements stacked on top of each other. In return countDown(n - 1); each call waits for the deeper call to return, then passes that value back up the chain. Tracing what a recursive method returns is one of the most common hard MCQs on the exam.

Data types (Unit 1)

The return type is just a data type attached to a method. Everything you know about int vs. double vs. String vs. boolean applies, including widening (returning an int where a double is expected is fine, but not the reverse).

Is Return Statement on the AP Computer Science A exam?

Multiple choice questions test return statements two main ways. One, they give you a method and ask what a specific call evaluates to, which means tracing the code until you hit a return. Two, they test the rules themselves, like what's required to call a non-void method or what happens when getBalance() is called from inside another method (the call evaluates to the returned value, which the caller can use). Recursion questions raise the stakes, since you have to track returns flowing back up through multiple stacked calls. On the FRQ side, you'll write methods with declared return types, like the 2017 Phrase class question, where methods access and modify a string and hand results back. Two habits earn points there. Return the right type on every path, and remember that return exits the method instantly, which is a clean way to stop a loop the moment you find what you're searching for.

Return Statement vs System.out.println (printing)

Printing and returning are completely different, and mixing them up costs FRQ points every year. System.out.println displays a value on the screen and gives nothing back to the program. return sends a value back to the calling code, where it can be stored in a variable or used in an expression, and it may never appear on screen at all. If an FRQ asks you to write a method that returns a String and you print it instead, you don't earn the point. A quick check is the method header. If the return type isn't void, the method needs a return statement, not a print statement.

Key things to remember about Return Statement

  • A return statement immediately ends the method and sends a value back to the exact spot where the method was called.

  • The returned value's type must be compatible with the return type declared in the method header, and every possible path through a non-void method must reach a return.

  • A method call to a non-void method evaluates to its returned value, so account.getBalance() can be stored in a variable or used directly in an expression.

  • Returning is not printing; return hands a value to the caller, while System.out.println only displays it, and FRQs grade you on returning.

  • Void methods return nothing, but you can still use a bare return; to exit one early.

  • In recursion, each call's return value feeds the call above it, so tracing returns up the call stack is how you find what a recursive method evaluates to.

Frequently asked questions about Return Statement

What is a return statement in AP Computer Science A?

A return statement ends a method's execution and sends a value back to the code that called it. The value must match the return type declared in the method header, like int or String.

Is return the same as printing in Java?

No. return passes a value back to the caller so the program can use it, while System.out.println only displays text and gives nothing back. On FRQs, if the method header has a non-void return type, you must return, not print.

Does code after a return statement still run?

No. The method stops the instant a return executes, and control jumps back to the caller. Unreachable code directly after a return won't even compile in Java, and an early return is a legit way to exit a loop the moment you find your answer.

Do void methods need a return statement?

No, void methods don't require one because they return no value. You're allowed to write a bare return; to exit a void method early, but you can never return an actual value from it.

How does a return statement work in a recursive method?

Each recursive call pauses and waits for the deeper call's return value. In return countDown(n - 1);, the base case (return 0; when n hits 0) returns first, and that value gets passed back up through every waiting call until the original caller gets the result.