Java Instantiation

后端 未结 3 2123
滥情空心
滥情空心 2020-12-14 04:27
  1. When an object is instantiated in Java, what is really going into memory?
  2. Are copies of parent constructors included?
  3. Why do hidden
3条回答
  •  清歌不尽
    2020-12-14 05:05

    1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and itssuperclasses. Implementation-specific data includes pointers to class and method data.

    2. The instance variables of the objects are initialized to their default values.

    3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its uppercase.This process continues until the constructor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java.

    4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then thebody of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

提交回复
热议问题