Home  >  Article  >  Java  >  Person p = new Person(); What does it do in memory?

Person p = new Person(); What does it do in memory?

(*-*)浩
(*-*)浩Original
2019-11-11 14:21:363322browse

Person p = new Person(); What does it do in memory?

Person p = new Person();What does it do in memory?

Load the Person.class file into memory.

If p is defined in the main method, then a variable space p will be opened in the stack space.

Allocate space for objects in heap memory.

Perform default initialization of members in the object.

Perform explicit initialization of members in the object.

Call the construction code block to initialize the object. (If not, it will not be executed)

Call the constructor to initialize the object. The object is initialized.

Assign the memory address of the object to the p variable and let the p variable point to the object.

The above is the detailed content of Person p = new Person(); What does it do in memory?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn