/* This program illustrates several difference between static objects and * dynamic objects. The syntax by which they are created differs; * dynamic objects use the 'new' operator. * * Static objects have their create() public and operator {} called before * main() executes; dynamic objects have their create() public and * {} operator called at the point the 'new' operator is executed. * * Oh, and static objects can be used as variable initializers. * * This program prints out the following lines: * * Creating 1 * Completing 1 * Beginning main() * Object 1, info is 100 * Creating 2 * Completing 2 * Object 2, info is 200 * * See if you can figure out why. */ /* Here's the class around which this sample revolves */ class myClass { /* CLASS PRIVATE VARIABLES */ var objNum; /* Initialized by the create public */ /* CLASS METHOD VARIABLES */ public var info = 0; /* Information about this object */ /* CLASS METHOD PROCEDURES */ public proc create(num) { objNum = num; say( "Creating ", objNum, "\n" ); } operator {} () { say( "Completing ", objNum, "\n" ); } public proc describe() { say( "Object ", objNum, ", info is ", info, "\n" ); } } proc main() { /* Print out a message when main executes */ say( "Beginning main()\n" ); /* Declare, define, and describe a static object */ var myObj = myClass(1) { info = 100 }; myObj.describe(); /* Declare, define, and describe a dynamic object */ var myOtherObj; myOtherObj = new myClass(2) { info = 200 }; myOtherObj.describe(); }