AP CSA 3.9 Exercise 2: The this Keyword Applied Practice

Unit 3: Class Creation · Lesson 3.9 · Exercise 2

The this Keyword: Applied Practice

Six scenarios on what this refers to and the one place it is mandatory rather than optional.

How this one is different

The exercise-1 editor asks you to use this. These six ask when leaving it out changes the behavior, which is precisely when a name is shadowed.

Applied Practice

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

Question 1 of 6Analyze
Inside an instance method, this is evaluated.
What does it refer to?
Incorrect. That would be super.
Incorrect. The class is not an object, and static members belong to it.
Correct. Correct. Two calls on two different objects see two different values of this.
Incorrect. Creation order plays no part.
Question 2 of 6Apply
A method has no parameter or local sharing a name with a field, and it refers to that field without this.
Is the code correct?
Incorrect. It is required only to break a shadow.
Correct. Correct, and some codebases still use it everywhere for consistency, which is a style choice.
Incorrect. It compiles and works.
Incorrect. The rule is the same in any instance method.
Question 3 of 6Analyze
A setter is written as public void setAge(int age) { age = age; }
What is the effect on the object?
Correct. Correct, and it is silent. The setter appears to work and the getter keeps returning the old value.
Incorrect. The field is not touched, so it keeps whatever it held.
Incorrect. Self-assignment compiles, though many tools warn about it.
Incorrect. That needs this.age on the left.
Question 4 of 6Apply
A constructor needs to invoke another constructor of the same class.
What is the syntax and constraint?
Incorrect. super calls a superclass constructor, and it too must come first.
Incorrect. Constructor chaining is standard.
Incorrect. That builds a separate object rather than initializing this one.
Correct. Correct. The first-statement rule ensures initialization happens exactly once and in order.
Question 5 of 6Evaluate
A method returns this.
What does that enable?
Incorrect. this is unavailable in static contexts entirely.
Incorrect. It is a deliberate and common pattern.
Correct. Correct: returning this is what makes a fluent builder style possible.
Incorrect. No copy is made; it is the same object.
Question 6 of 6Apply
A programmer uses this inside a static method.
What happens?
Incorrect. There is no reference to the class available under that name.
Correct. Correct, and it is the same underlying reason a static method cannot read instance fields.
Incorrect. It has no value at all rather than a null one.
Incorrect. No such association exists.

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]