Local Variable: In Java, a local variable is typically used inside a method, constructor, or a block and has only local scope. Thus, this variable can be used only within the scope of a block. The best benefit of having a local variable is that other methods in the class won’t be even aware of that variable.
Access modifiers cannot be used for local variables. Local variables are implemented at stack level internally. There is no default value for local variables, so local variables should be declared and an initial value should be assigned before the first use.
Example:
public void myFunction()
{
String myLocalVariable = "ProgramsBuzz";
}
Instance Variable: An instance variable in Java, is a variable which is bounded to its object itself. These variables are declared within a class, but outside a method. Every object of that class will create its own copy of the variable while using it. Thus, any changes made to the variable won't reflect in any other instances of that class and will be bound to that particular instance only.
class Test
{
public String myInstanceVariable;
public void myFunction()
{
}
}