AP CSA 3.5 Exercise 2: Methods: How to Write Them Applied Practice

Unit 3: Class Creation · Lesson 3.5 · Exercise 2

Methods: How to Write Them: Applied Practice

Six scenarios on signatures, return types, and the difference between printing a value and returning one.

How this one is different

The exercise-1 editor asks you to write methods. These six ask what the CALLER receives, because a method that prints instead of returning is the most common way a correct calculation becomes unusable.

Applied Practice

6 questions · scenario driven · every answer is recorded for your teacher

Question 1 of 6Analyze
A method computes a total and prints it, declaring a void return type. The caller needs the total for further arithmetic.
What is the problem?
Incorrect. Staticness is unrelated to returning a value.
Incorrect. Output is for humans. The program cannot recover it.
Correct. Correct, and this is the single most common shape error in student methods.
Incorrect. void restricts only what comes back, not what happens inside.
Question 2 of 6Apply
A method is declared to return int but one path through its body reaches the end without a return.
What happens?
Incorrect. Fields have defaults; return paths do not.
Correct. Correct, and it usually appears when a return is placed inside an if without a matching else.
Incorrect. An int cannot be null, and the code never compiles anyway.
Incorrect. The compiler rejects it first, which is the helpful outcome.
Question 3 of 6Analyze
A method takes an int parameter and modifies it inside the body. The caller then prints its own variable.
What does the caller see?
Correct. Correct, and the contrast with objects, where the copied REFERENCE still points at the caller's object, is 3.6.
Incorrect. Nothing zeroes the caller's variable.
Incorrect. Modifying a parameter is legal.
Incorrect. That would require reference semantics, which primitives do not have.
Question 4 of 6Apply
Two methods in one class are named the same but take different parameter types.
Is that legal?
Incorrect. Differing return types alone are not enough and will not compile.
Incorrect. Ordinary methods overload just as constructors do.
Incorrect. Names may repeat when the parameter lists differ.
Correct. Correct, and note the return type is NOT part of the signature.
Question 5 of 6Evaluate
A method has eight parameters.
What does that usually indicate?
Incorrect. Java permits it.
Incorrect. A long list is a reliable signal worth heeding.
Correct. Correct, and it also makes call sites easy to get wrong when the types repeat.
Incorrect. Parameter count has no bearing on staticness.
Question 6 of 6Apply
A method must report both a result and whether the operation succeeded.
Which approach fits Java?
Incorrect. Java methods return exactly one value.
Correct. Correct, and a sentinel only works when it cannot be confused with a legitimate result.
Incorrect. A method has one return type.
Incorrect. Printing makes half the answer unavailable to the caller.

Where to go next

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]