Card 41 / 76: What is the scope of an instance variable?
A)
The block of code in which it is declared.
B)
The method for which it is a parameter.
C)
The class in which it is declared.
Answer:
C) The class in which it is declared.
Previous Card | ← Previous Card Button |
Next Card | → Next Card Button |
Flip Card | Space-Bar |
It is in scope for the entire class, and its lifecycle is tied to that class.
A and B are incorrect.
A is incorrect because local variables are in scope for the block of code in which they are declared.
B is incorrect because method parameters are in scope for the entire method.
|