|
Is the scope of a local variable always the entire body of a method? A good answer might be:No---only from where the variable was declared until the end of the body. Sometimes a local variable is declared in the middle of the body, close to the statement which first uses it. | |
Can't use the Same Name in the Same ScopeIt is a mistake to use the same identifier twice in the same scope. For example, the following is a mistake:
The scope of the formal parameter (amount) overlaps the scope of the local variable ( also named amount), so this is a mistake. This is a different situation than the previous one where two separate formal parameters were both named amount. In that situation the scopes did not overlap and there was no confusion. | |
QUESTION 10:Can the same identifier be used as an name for a local variable in two different methods? Click Here after you have answered the question |