/** * Scope.java * Ying Li * 02/23/2020 */ public class Scope { private static int stayWithMe = 0; // class variable, class scope // private int stayWithMe = 10; // not legal private int field; // instance variable, class scope // prameter field has constructor scope public Scope (int field) { // "field" is at function-level scope // "this.field" is stored in the object named "this". Other methods in this class can access it. this.field = field; //int stayWithMe = 3; // shadowing, sort of. function-level scope stayWithMe += 1; // avoid shadowing with better syntax Scope.stayWithMe += 1; // SRT favorite syntax this.stayWithMe += 1; } public static void main (String argv[]) { Scope s1 = new Scope(3); Scope s2 = new Scope(4); System.out.println( s1.field ); System.out.println( "stayWithMe " + Scope.stayWithMe ); System.out.println( "stayWithMe " + s1.stayWithMe ); } }