The Instantiation Process at Runtime

Contact Us or call 1-877-932-8228
The Instantiation Process at Runtime

The Instantiation Process at Runtime

In general, when an object is instantiated, an object is created for each level of the inheritance hierarchy. Each level is completed before the next level is started, and the following takes place at each level:

  1. The memory block for that level is allocated (for derived classes, this means it is sized for the added elements, since the inherited elements were in the base class memory block.
  2. The entire block is zeroed out.
  3. Explicit initializers for that level run, which may involve executable code, for example: private double d = Math.random();
  4. The constructor for that level runs. Note:
    • Since the class code has already been loaded, and any more basic code has been completed, any methods in this class or inherited from superclasses are available to be called from the constructor.
    • Note that if this level's constructor calls a superconstructor, all you are really doing is selecting which form of superconstructor will run at the appropriate time. Timing wise, that superconstructor was run before we got to this point.

When the process has completed, the expression that created the instance evaluates to the address of the block for the last unit in the chain.

Inheritance and static Elements

static methods in a class may not be overridden in a derived class. This is because the static method linkages are not resolved with the same dynamic mechanism that non-static methods use. The linkage is established at compile time.