AP CSA 3.6 Exercise 2: Methods: Passing and Returning Object References Applied Practice

Unit 3: Class Creation · Lesson 3.6 · Exercise 2

Methods: Passing and Returning Object References: Applied Practice

Six scenarios on what actually travels when an object is passed, and why the answer differs from primitives.

How this one is different

This is the topic where "Java is pass by value" stops sounding like a contradiction. These six ask what the CALLER observes after a method runs.

Applied Practice

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

Question 1 of 6Analyze
A method receives an ArrayList parameter and calls add on it. The caller then prints its own list size.
What does the caller see?
Incorrect. Nothing clears the list.
Incorrect. This is ordinary legal code.
Incorrect. The REFERENCE is copied; the object is not.
Correct. Correct, and it is why passing a mutable object hands out real modification rights.
Question 2 of 6Apply
A method receives an object parameter and REASSIGNS it to a brand new object.
What does the caller observe?
Incorrect. Objects do not merge.
Incorrect. That would require Java to pass the reference itself by reference, which it does not.
Correct. Correct. This is the precise sense in which Java is pass by value: the VALUE copied is the reference.
Incorrect. Nothing becomes null.
Question 3 of 6Analyze
A method returns a reference to an object the class holds in a private field.
What can the caller do with it?
Incorrect. The reference carries every public method, mutators included.
Correct. Correct, and returning a defensive copy is the fix when that is not wanted.
Incorrect. A reference is not a data copy.
Incorrect. Comparison is one option among many.
Question 4 of 6Apply
Two variables are assigned the same object, then a method is called on one of them that changes a field.
What does the other variable show?
Correct. Correct. Assignment between object variables copies the reference, not the object.
Incorrect. Neither reference becomes null.
Incorrect. No copy is made on assignment.
Incorrect. There is only one object to change.
Question 5 of 6Evaluate
A method takes a String parameter and calls replace on it without assigning the result.
Does the caller's String change?
Incorrect. No characters change in the original.
Incorrect. Discarding a return value is legal.
Incorrect. Even with a shared reference, an immutable object offers no mutating operation to call.
Correct. Correct, and it is why String feels like it behaves as a primitive when passed.
Question 6 of 6Apply
A class wants to hand out its internal list without letting callers modify it.
What is the standard approach?
Incorrect. Returning null forces every caller into a null check and provides no data.
Incorrect. Documentation does not prevent anything.
Correct. Correct: a defensive copy. Note the ELEMENTS are still shared, so this protects the list structure rather than the objects in it.
Incorrect. A private method cannot serve outside callers at all.

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]