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 class oop_05{public static void Main (string[] args) { Animal a = new Animal (ten); M_1 (a); System.out.println ("main----->" + a.age); System.out.println (a); } public static void M_1 (Animal a) { a.age++; System.out.println ("M_1--->" + a.age);} Class animal{ //field int age; Constructor Animal (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
Talking about javase memory flowchart