Variables scope

A java variable might live inside three different scopes during a specific lifetime

Local scope

The scope of method and initializer blocks.

At the end of the block's execution, the variable is destroyed.

Instance scope

Here, the variable's lifespan depends upon the instantiated object in which it lives. if the object is destroyed, the variable will too.

Class scope

If a field is declared static, it is going to live until the program terminates.