Return Statement in AP Computer Science A
In AP Computer Science A, a return statement uses the `return` keyword to send flow of control back to where a method was called. In a non-void method it also sends back a single value compatible with the header's return type. Any code after it in sequence never runs.
This definition is part of Fiveable's AP Computer Science A review, which also has guided practice questions.
What is Return Statement?
A return statement is how a method hands its answer back to whoever called it. When Java hits return, the method stops right there and control jumps back to the line that made the call. Per the CED (EK 3.5.A.4), any code sequentially after a return statement will never be executed.
What gets returned depends on the method's header. A non-void method has a return type (like int, double, or String) where void would go, and it must return a single value compatible with that type (EK 3.5.A.2, 3.5.A.3). Java evaluates the expression after return and sends back a copy of the result. The CED calls this return by value. A void method returns no value (EK 3.5.A.1), but it can still use a bare return; to exit early. Think of return as the method's exit door. Non-void methods carry a value out through it, and void methods just walk out.
Why Return Statement matters in AP® Computer Science A
Return statements show up in two places in the CED. In Unit 1 (Topic 1.9), you're on the calling side. Learning objective 1.9.B asks you to describe how to call methods, and EK 1.9.B.2 says a returned value must be stored in a variable or used in an expression, or it's lost. In Unit 3 (Topic 3.5), you're on the writing side. Learning objective 3.5.A asks you to develop methods and determine the result of calling them, which means writing correct return types, correct return expressions, and knowing exactly when a method stops.
This matters for the exam because almost every code-tracing MCQ and every method-writing FRQ depends on it. If you misread where a method exits or what it hands back, your traced output is wrong.
Keep studying AP® Computer Science A Unit 2
How Return Statement connects across the course
Method Signature and Return Type (Units 1, 3)
The return type in the header is a promise, and the return statement keeps it. If the header says double, every return path has to send back something compatible with double. That's why reading the header (1.9.A) tells you what a call will produce before you ever look at the body.
Call by Value (Units 1, 3)
Values flow into a method as copies through parameters and flow out as copies through return. Changing a parameter inside the method doesn't change the caller's variable. The only way a primitive result gets back to the caller is through the return value, and only if the caller actually stores or uses it.
Void Methods and Early Return (Units 1, 3)
A void method can't return a value, but return; still works as an emergency exit. That lets you skip the rest of the method when a condition is met, which is exactly the kind of control flow tracing questions love to test.
Instance Variables and Mutator Methods (Unit 3)
Inside a class, methods split into two jobs. Accessor-style methods return information about an object's instance variables, and mutator methods change those variables and are often void. Knowing which job a method has tells you whether you need a return statement at all.
Is Return Statement on the AP® Computer Science A exam?
Expect return statements in code-tracing MCQs and in FRQ method writing.
- Multiple returns in one method. A method like
analyzeTemperature(double temp)might have severalifblocks, each with its ownreturn. The first condition that's true wins, and the method stops there. Later checks never run. - Ignored return values. In a classic setup,
modify(num);is called on its own line and the result is thrown away. The caller'snumdoesn't change because of call by value, sonumstill prints as4. Thenmodify(num)inside the print statement returns(4 + 3) * 2, which is14. - Early return in a void method. If
process(int n)printsnand then hitsreturn;whenn <= 2, the"X"only prints for larger values. Calls with 4, 2, and 1 produce4X21. - Return type mismatches. A method meant to return the exact decimal average of two
intparameters needs adoublereturn type and must avoid integer division, for example by dividing by2.0.
On FRQs, you write full methods with correct return types and returns on every path. The 2017 FRQ Q3 (the Phrase class) had you write methods that access and modify a string stored in an instance variable, which is exactly where getting return statements right earns points.
Return Statement vs Printing (System.out.print)
Printing displays text on the screen for a human to read. Returning hands a value back to the calling code so the program can keep using it. A method that prints a result but doesn't return it gives the caller nothing to store, and a method that returns a value doesn't display anything unless the caller prints it. On FRQs, if the prompt says a method "returns" something, printing it instead won't earn the point.
Key things to remember about Return Statement
A return statement immediately ends the method and sends control back to the line that called it.
Any code that comes sequentially after a return statement in the same block will never execute.
A non-void method must return a single value that is compatible with the return type in its header.
A void method returns no value, but it can use a bare
return;to exit early.When you call a non-void method, the returned value is lost unless you store it in a variable or use it in an expression.
Java returns by value, so the caller gets a copy of the result, and changing a parameter inside a method does not change the caller's variable.
Frequently asked questions about Return Statement
What is a return statement in AP Computer Science A?
It's a statement using the return keyword that ends a method and sends control back to where the method was called. In a non-void method, it also sends back a value matching the header's return type (EK 3.5.A.3, 3.5.A.4).
Can a void method have a return statement?
Yes. A void method can use return; with no value to exit early, but it can never return an actual value. Writing return 5; in a void method is a compile error.
Does code after a return statement run?
No. Once Java executes a return, the method is done, and any code sequentially after it never executes. That's why a method with several if blocks that each return stops at the first true condition.
What's the difference between return and System.out.print in Java?
print shows output on the screen, while return gives a value back to the calling code. If an FRQ says a method should return a value, printing it instead is wrong because the caller receives nothing.
If I call a method and don't use the return value, what happens?
The value is simply discarded. Per EK 1.9.B.2, you must store it in a variable or use it in an expression to keep it. Calling modify(num); alone won't change num either, because Java passes primitives by value.
Keep studying AP Computer Science A
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
AP Computer Science A hub
Review units, study guides, and course resources.
AP-style practice
Check this vocabulary in multiple-choice context.
FRQ practice
Apply key concepts in written AP responses.
Score calculator
Estimate the exam score you are working toward.
Cheatsheets
Review the highest-yield facts before practice.
Practice exam
Put the full course together before test day.