AP CSA Unit 3 Day 22: This In Constructors

Unit 3, Classes & Objects • Cycle 2
Day 22 Advanced Practice • Harder Difficulty
Focus: this in Constructors Hard this in Constructors

Advanced Practice Question

Format: this in Constructors

What is the output?
public class Circle {
    private double radius;
    
    public Circle(double radius) {
        this.radius = radius;
    }
    
    public double getRadius() {
        return radius;
    }
}

// In another class:
Circle c = new Circle(5.0);
System.out.println(c.getRadius());
Difficulty: Hard | Topic: this in Constructors | Cycle: 2 (Advanced)
Why This Answer?

this.radius refers to the instance variable, radius (parameter) refers to the parameter. The assignment stores 5.0 in the instance variable.

Common Mistake
Watch Out!

Thinking this.radius and radius are always the same thing.

AP Exam Strategy

this. distinguishes instance variables from parameters/locals with the same name.

Master This Topic

This Cycle 2 HARD question tests this in constructors. Review Unit 3 concepts to build mastery of classes & objects.

  • Understanding this in constructors
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 3 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.