Instructions: This is an ungraded fill-in-the-blank exercise. Each question consists of a sentence with one or two words left out. A button represents the missing word(s). For each question, think of the word or phrase that should fill each blank, then click on the buttons to see if you are correct. No grade is calculated for this exercise.
This exercise reviews the "scope" of variables and parameters. The scope of a variable or formal parameter is the section of code that can "see" (can use) the parameter.
The scope of an instance variable includes each method body (list of statements) and each constructor body.
"Outsiders" can access instance variables of an object using "dot notation" unless the instance variable is private (or has default access and is in a different package...but ignore this for now.)
Formal parameters can only be seen by the body of their own method.
It is OK for formal parameters in two different methods to use the same identifier.
A local variable can only be seen in the body of its method by statements following its declaration. It is OK for local variables in different methods to use the same name.
If a local variable has the same name as an instance variable the local variable will be the one seen by the statements in its method that follow its declaration. (Although it is correct syntax to have both local and instance variables use the same name, it is probably a bad idea since it confuses humans.)
If a local variable has the same name as an instance variable and you want to specify the instance variable, use this.
If a paramenter has the same name as an instance variable and you want to specify the instance variable, use this. This is often done with constructors, where it is probably less confusing to use the same name for both.
An "outsider" can change a private instance variable of an object by using an access method of the object (if there is one.)