/* Author: James Tam Version: 2015 Learning objectives: 1) Scope of attributes (static and non-static). 2) Scope of locals. */ public class Foo { public static int x = -1; private int y; // x, y accessible here // newX, z not accessible public Foo() { y = 1; System.out.print(x + " " + y); } // x, y accessible here // newX: a parameter, also a local variable // z: local variable // Both: accessible only inside the scope of the method public void setX(int newX) { int z = 0; System.out.println(x + " " + y + " " + z); } // x, y accessible here // newX not accessible // z: local to this method, not the same as the one in setX() public void anotherMethod() { int z = 1; System.out.println(x + " " + y + " " + z); } }