import java.io.*; public class Static implements Serializable { //static int numInstances = 0; int numInstances = 0; public static void main (String[] args) { Static anObject; FileOutputStream file; ObjectOutputStream freezer; // create a test object anObject = new Static(); System.out.println("Original object : " + anObject); // freeze it as an external file "static.ser" try { file = new FileOutputStream("static.ser"); freezer = new ObjectOutputStream(file); freezer.writeObject( anObject ); freezer.close(); } catch (IOException noIO) { System.out.println("IO error occurred: " + noIO); } } //------------------------------------------------------------------- // Static constructor //------------------------------------------------------------------- public Static() { numInstances++; // track how many times they create us } } // End of Class Static