Unable to access a method's local variables outside of the method in Java
问题 I am new to Java and am trying to access method variables outside of the method, but it doesn't work. Code is below: public class MethodAccess { public static void minus() { int a=10; int b=15; } public static void main(String[] args) { //Here i want to access variable names a & b that is in minus() int c = b - a; } } 回答1: 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