Java examples for Language Basics:Hello World
A block is marked by a matching pair of braces.
public class ScopeApp{ static int x; public static void main(String[] args) {/*from w ww. j av a 2 s .c o m*/ x = 5; System.out.println("main: x = " + x); myMethod(); } public static void myMethod() { int y; y = 10; if (y == x + 5) { int z; z = 15; System.out.println("myMethod: z = " + z); } System.out.println("myMethod: x = " + x); System.out.println("myMethod: y = " + y); } }