# StaticFieldTested.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-02 File created. # 2022-12-27 Converted to Python 3. # This program demonstrates a kind of static field of a class. class TestClass : number_of_objects_created = 0 def __init__( self ) : TestClass.number_of_objects_created += 1 def print_status( self ) : print( "\n %d objects created" % TestClass.number_of_objects_created, end="" ) # The main program first_object = TestClass() first_object.print_status() second_object = TestClass() first_object.print_status() third_object = TestClass() first_object.print_status() fourth_object = TestClass() third_object.print_status() print( "\n\n %d objects created" % TestClass.number_of_objects_created )