Source of StaticDemo.java


  1: 
  2: public class StaticDemo
  3: {
  4:     private static int numberOfInvocations = 0;
  5:     
  6:     public static void main(String[] args)
  7:     {
  8:         int i;
  9:         StaticDemo object1 = new StaticDemo( );
 10:         for (i = 1; i <=10 ; i++)
 11:            object1.outPutCountOfInvocations( );
 12:         StaticDemo object2 = new StaticDemo( );
 13:         for (i = 1; i <=10 ; i++)
 14:            object2.justADemoMethod( );
 15:         System.out.println("Total number of invocations = "
 16:                            + numberSoFar( ));
 17:     }
 18:     
 19:     public void justADemoMethod( )
 20:     {
 21:         numberOfInvocations++;
 22:         //In a real example, more code would go here.
 23:     }
 24:     
 25:     public void outPutCountOfInvocations( )
 26:     {
 27:         numberOfInvocations++;
 28:         System.out.println(numberOfInvocations);
 29:     }
 30:     
 31:     public static int numberSoFar( )
 32:     {
 33:         numberOfInvocations++;
 34:         return numberOfInvocations;
 35:     }
 36: }