AP Computer Science A Flashcards: Scope and Access
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.
What happens when a local variable and an instance variable share the same name within a method's body?
The variable name will refer to the local variable, effectively hiding the instance variable within that scope.
Card 1 of 10
All Flashcards (10)
What happens when a local variable and an instance variable share the same name within a method's body?
The variable name will refer to the local variable, effectively hiding the instance variable within that scope.
In programming, what does the term 'scope' explain?
Scope explains where variables can be used or accessed within the code.
A method has a parameter `int score`, and its class has an instance variable also named `int score`. Inside that method, which variable does `score` refer to?
The name `score` will refer to the local parameter, not the instance variable.
If a variable `x` is declared inside a method, can it be used outside of that method?
No, because as a local variable, its scope is limited to the block (the method) in which it was declared.
What is the term for when a local variable has the same name as an instance variable, causing the local one to be used instead?
This is known as variable shadowing, where the local variable's name takes precedence over the instance variable's name in the local scope.
A constructor has a parameter `id`. If there is also an instance variable named `id`, what does the name `id` refer to inside the constructor body?
Inside the constructor body, the name `id` will refer to the local parameter, not the instance variable, due to scope rules.
What is the primary rule governing the accessibility of a local variable?
A local variable can only be accessed within the specific block of code in which it was declared.
Define 'local variable'.
A local variable is a variable declared in the headers or bodies of blocks of code.
What is the scope of a local variable?
The scope of a local variable is the block of code in which it is declared.
Where are local variables declared?
Local variables are declared in the headers or bodies of blocks of code, such as methods or constructors.