I am new to Java and am trying to access method variables outside of the method, but it doesn\'t work.
Code is below:
Because a and b are local variables.
If you want to access to them in your main method, you need to modify your code. For example :
public class methodacess {
private static int a;
private static int b;
public static void minus(){
methodacess obj =new methodacess();
a=10;
b=15;
}
public static void main (String[] args){
int c = b - a;
}
}