jvm이 실행될 때 .class 파일을 가져와서 static를 먼저 찾습니다. 이때, 메모리 공간에 static가 올라갑니다. 이제 jvm은 올라가 있는 메모리 공간을 3개로 나누고 static를 먼저 넣습니다. 그리고 static이 존재하는 class별로 나누어서 저장합니다. 각 class마다 저장된 공간에는 static으로 지정된 변수를 담아놓습니다. 이후에 main이 실행됩니다. 만약 static를 사용하지 않는다면, 메모리에서 해당 변수를 찾을 수 없습니다.

이러한 과정을 통해 jvm은 .class 파일을 가져와서 메모리에 올리고, static 변수를 적절한 위치에 저장하여 프로그램을 실행시킵니다.

public void main(String[] args)
//static 가 안붙어있음

public static void main(String[] args)
//커스텀 자료형
//static
class Person1 {
    static int age = 20;
    static char gender = '여';
}

public class MemEx01 {
    public static void main(String[] args) {
        System.out.println(Person1.age);
        System.out.println(Person1.gender);
    }
}

<aside> 💡 static를 선언하면 main이전 부터 메인이 끝날 때 메모리에서 사라짐

static = 정적 할당

</aside>