The instantiation process is divided into two steps:
(Recommended tutorial: java introductory tutorial)
First declare the object , is to open up a space in the stack, name it the name of the object, and the content inside is null;
Then use new to open up a space in the heap, the object in the heap is the object, and then put the heap The address in the space is stored in the stack, so that the object can be used, such as
A aNew=new A();
(Video tutorial recommendation: java video tutorial)
aNew is in the stack The name of the space, new A() is to open up space in the heap, and then assign the address in the heap to the aNew space, which is equivalent to giving the key to aNew, then aNew can operate on the space in new A() at will. , somewhat similar to pointers in C language.
The above is the detailed content of Analyze the process of object instantiation. For more information, please follow other related articles on the PHP Chinese website!