BALS BALS - 1 year ago 50
Java Question

What happens during Java object initialization

After I read many article in internet.I assumed object initialization is actually allocating object memory in heap but I couldn't be sure about it .
Please anyone explain me what happens behind the scene of object initialization or give me an reference link.

Answer Source

Java doesn't actually allocate space until a 'new' object is created. Declaring a reference for an object does not allocate memory on the heap.

When a first instance of a new object is created - the initialization of the class / interface (static members, etc.) happens in the order provided in the Java Specification (See section 12.4)

Then the instance of the object initialization things happen as referenced in Section 12.5 of the same document.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download