Attempting to access a local variable from a nested method. : variable scope « Java Source And Data Type « SCJP






class MainClass{
           public static void main(String [] args) {
             MainClass s = new MainClass();
             s.go();
           }
           void go() {
             int y = 5;
             go2();
             y++;        // once go2() completes, y is back in scope
           }
           void go2() {
             y++;        // won't compile, y is local to go()
           }
         }
y cannot be resolved








1.26.variable scope
1.26.1.Variable Scope
1.26.2.Attempting to access an instance variable from a static context.
1.26.3.Attempting to access a local variable from a nested method.
1.26.4.Attempting to use a block variable after the code block has completed.
1.26.5.Primitive and Object Type Instance Variables
1.26.6.Initialization Blocks