Make your own free website on Tripod.com
 1:class scopetest
 2:{
 3:   public static void main(String args[])
 4:   {
 5:        {
 6:           int i=0; //scope within the block
 7:           System.out.println("block"+i);
 8:           
 9:        }
10:        if(true)
11:        {
12:           int j=2; //scope is within the if statement(braces)
13:           System.out.println("if"+j);
14:        }
15:        int sw=0;
16:        switch(sw)
17:        {
18:                case 0: {int s0=2; } //scope is within the block(braces)
19:                case 1:
20:                case 2:
21:                case 3: { int s0=2; }//scope is within the block(braces)
22:                case 4:
23:        }
24:        //i=0;  these two statements will give an error because i,j out of scope
25:        //j=0;
26:        s0=0;
27:   }
28:}
29: