If I declare a variable in a java method, is that variable also accessible to any method called from the method in which it is declared?
When I try the following, function2 does not recognise the variable variable1. Should this be the case?
public static void main(String[], args)
{
int variable1
function2();
}
When I try the following, function2 does not recognise the variable variable1. Should this be the case?
Yes. It's a local variable - local to the method in which it's declared. That method could be executing several times within the same thread (different stack levels) and on several different threads - each invocation of the method has a separate variable.
You should review the Variables section of the Java tutorial.
See more on this question at Stackoverflow