/* StaticTest.java defines a class with a static data member which gets incremented every time an object of the class is constructed. *Note: we get to the static variable in foo class via the classname foo NOT via a ref var of the class */ public class StaticTest { public static void main(String args[] ) { System.out.println("numObjects before any created: " + Foo.numObjects ); Foo f1 = new Foo(); Foo f2 = new Foo(); Foo f3 = new Foo(); Foo f4 = new Foo(); System.out.println("numObjects after some objects created: " + Foo.numObjects ); } // END main } // we put our class defintion inside our app file again class Foo { public static int numObjects; Foo() { ++numObjects; // increment static object counter System.out.println("Just constructed foo object " + Foo.numObjects ); } }