Let’s learn scope and lifetime of variables in java.
Scope and lifetime of variables in java
I have discussed variables in java in my earlier post. Now let’s learn the scope and lifetime of variables.
Local variable scope is within the block where it is declared and lifetime is until control exits the block in which local variable is declared.
Instance variable scope is throughout the class except static methods and lifetime is until object is there in memory.
Static variable scope is throughout the class and the lifetime is until the end of java program.
Also read – major features of java