ScopeExample

 


public class ScopeExample {

/**
* @param args
*/
public static void main(String[] args) { // begin main method code block
// Demonstrate block scope.

int var1; // Visible in ....
int var3 = 30;

var1 = 10;

if(var1 == 10)
{ // begin new code block

int var3 = 12; // what is wrong here?
int var2 = 20; // Visible in...

System.out.println("var1 and var2 : "+ var1 +""+ var2);
}

var2 = 100; // Why is there an error here?

System.out.println("var1 and var2 : "+ var1 +""+ var2);

System.out.println("var1 is " + var1);
System.out.println("var3 is " + var3);




} // end of main method
} // end of class