You should check out some articles on scope in Java.
Instance Variables
Variables defined within in a class itself and not in a constructor or method of the class.They are known as instance variables because every instance of the class (object) contains a copy of these variables. The scope of instance variables is determined by the access specifier that is applied to these variables.
public class StudentChart{
//instance variable private is the "access modifier" you can make it public, private protected etc.
private int[] results;
Argument Variables
These are the variables that are defined in the header of constructor or a method. The scope of these variables is the method or constructor in which they are defined. The lifetime is limited to the time for which the method keeps executing. Once the method finishes execution, these variables are destroyed.
public int foo(int argumentVariable)
public class Foo{
public Foo(int constructorVariableArgument)
constructorVariable = constructorVariableArgument
}
Local Variables
A local variable is the one that is declared within a method or a constructor (not in the header). The scope and lifetime are limited to the method itself.
public void foo(){
int methodVariable = 0;
}
Loop Variables
Loop variables are only accessible inside of the loop body
while(condition){
String foo = "Bar";
.....
}
//foo cannot be accessed outside of loop body.