Provide additional meaning, such as static behavior, finality, synchronization, etc.

  • they are loaded into memory when the class is first loaded (usually when it’s first accessed or used), and they stay loaded until the class is unloaded — typically at program termination
  • can use multiple of them at the same time
ModifierApplies ToMeaning (설명)
staticFields, methods, blocks, inner classesBelongs to the class instead of instances
finalVariables, methods, classesCannot be changed/overridden/inherited
abstractClasses, methods
- Abstraction - Classes & Interfaces
Class cannot be instantiated; method has no implementation and must be overridden by subclasses
(there are more)

Static Members

Static vs instance members

구분static 멤버인스턴스 멤버
메모리 영역클래스 영역힙 영역
접근 방식클래스명.멤버객체.멤버
공유 여부모든 인스턴스 간 공유객체마다 별도 보유
생성 시점클래스 로드 시new 생성 시
사용 예시공통 속성, 유틸리티 메서드객체의 개별 상태 관리

Static Members Initialization Order

  • Instance Initialization Block
    • a block of code inside a class but outside any method or constructor, written simply as { ... }
    • runs every time an object (instance) of the class is created, before the constructor is executed

Static member initialization order:

순서단계설명 (Korean)Description (English)
1JVM 기본값static 변수에 자료형에 맞는 기본값이 할당됨JVM gives default values to static fields (e.g. 0, null, false)
2명시적 초기화static 변수에 대입한 초기값 실행Static fields with assigned values get initialized
3static 초기화 블록static {} 안의 코드 실행static {} block runs for more complex logic
class Example {
    static int a;              // 기본값 0
    static int b = 10;         // 명시적 초기화
    static {
        a = 100;               // static 초기화 블록
    }
}