Attempting to use a block variable after the code block has completed. : variable scope « Java Source And Data Type « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Java Source And Data Type » variable scope 
1.26.4.Attempting to use a block variable after the code block has completed.
public class MainClass{
    public static void main(String[] argv){
       aMethod();
    }
    static void aMethod() {
       for(int z = 0; z < 5; z++) {
           boolean test = false;
           if(z == 3) {
               test = true;
               break;
           }
       }
       System.out.print(test);   // 'test' is an ex-variable,
                                 // it has ceased to be...
    }
}
test 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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.