Recently contacted OOP object-oriented, learning OOP, this, super, package, extends and override, overall if not clear memory of the process, the knowledge will be very confusing, with the teacher's help, took a picture, Can clearly identify the process of code in memory
Memory is roughly divided into four regions: 1, static data area 2, Stack 3, heap 4, static data area
Coding, compiling, calling to run, loading the JVM is not a detail, everyone should be clear.
The code first opens up space and name in the static code segment, then approaches and opens up space in the stack memory, opens up space in memory, copies the corresponding class into the heap memory, assigns values to the code operations of the constructor, and finally copies the addresses of the objects in the heap memory to the corresponding class variables.
Specific example code:
Public classoop_05{ Public Static voidMain (string[] args) {Animal a=NewAnimal (Ten); M_1 (a); System. out. println ("Main----->"+a.age); System. out. println (a); } Public Static voidm_1 (Animal a) {a.age++; System. out. println ("m_1--->"+a.age); }}classanimal{//Field intAge ; //ConstructorAnimal (int_age) { Age=_age; }}
To understand the process, you must first know what the composition of the class is: roughly divided into nine classes, 1, the Entry Method 2, the static variable 3, the static method 4, the member variable 5, the member method 6, the construction method 7, the static code segment 8, the member code segment 9, the abstract method
You should know that in-memory data cannot be accessed across domains, or you will get an error, static methods cannot call non-static methods
The calling method must first open the stack frame
This is roughly the case, please point out if there is a mistake. Thank you!
Talking about javase memory flowchart