SDSU CS535 Object-Oriented Programming & Design
Fall Semester, 1996
Final is not Static

[To Lecture Notes Index]
San Diego State University -- This page last updated Thursday, 19 September, 1996
----------

Contents of Final is not Static


Final is not Static Slide # 1Listen Here!
Final is not Static

import sdsu.io.Console;

class Test 
{
   public static void main( String args[] )
   {
   StaticTest a = new StaticTest();
   StaticTest b = new StaticTest();
   StaticTest c = new StaticTest();
   Console.println( "a's ID: " + a.myID );
   Console.println( "b's ID: " + b.myID );
   Console.println( "c's ID: " +c.myID );
   Console.println( "c's security code: " + c.securityCode );
   }
}

class StaticTest
{
   public final int myID = IdRegistry.getNewID();
   public final int securityCode = myID * 13;
}

class IdRegistry
{
   private static int unusedId = 0;
   
   public static int getNewID()
   {
      return unusedId++;
   }
}
Output
a's ID: 0
b's ID: 1
c's ID: 2
c's security code: 26


----------