25 Sep 2014
Scope of Variables in java
Instance and Static Variables : The scope of variables belongs to instance is entire class. The scope of static variables is also entire class. They can be declared any where in the class.
Local Variables : The scope of local variables start from its declaration and remain valid till the end of the block that contains the variable.
Note :
- A local variable must be initialized explicitly before it is used
- A local variable can be declared multiple times with the same name in different non-nesting blocks in a method
- A local variable can’t be declared multiple times with the same name in nested blocks
No Responses