An object has a lifetime from its time of creation to the time of its destruction. While it is alive, the object maintains the values of its internal variables unless they are altered by assignment. The conjunction of all the values of all the internal variables (private or public) is the state of the object. Since class variables can be of any type, some objects contain other objects, these being the values of those variables.Some objects have indefinite lifetime because they maintain their state for the whole lifetime of the program - these are global variables. Objects created during function call have a definite lifetime - these are local variables. Dynamic allocation allows the lifetime of an object to be controlled by program execution.
Copyright © 2003 Roger Hartley