according to me variables defined within a method are local variables and their scope is limited only to the scope of the method or block in which they are declared.
what happens is that when a class is instantiated, the instance calls for the default constructor if no other constructor is explicitly defined in the coding. instance variables defined in the class are considered to be taken within the constructor and a constructor initialises all the uninitialised instance variables to zero. thus variables defined by a method or a block can't become a part of the constructor and therefore are not initialised to zero.
for eg.
class A
{
int i,j;
void getValues()
{
int a=20;
int b=30;
int c=a+b;
System.out.println("the values of a and b are :"+a+" "+b);
System.out.println("the total is :"+c);
}
public static void main(String[] args)
{
A obj=new A();
System.out.println("the default values of i and j are :"+obj.i+" "+obj.j);
obj.getValues();
}
}
here what happens is that when we write
A obj=new A();
the A() goes and looks for a matching constructor as we are making a call to a constructor with no parameters.but since it does not find any match as none is explicitly declared, it calls implicitly the default constructor and the instance variables
int i,j become members of this default constructor and are initialised to zero.
but again if we have explicitly declared a constructor with or without parameters it will look for a match accordingly at the point of call.