인스턴스에 해당되지 않고, 클래스에 해당되는 '클래스 변수'도 존재

클래스 변수를 정의하기 위해서는 static이라는 키워드를 붙여주면 된다.

public class Person {
    static int count;
}

public static void main(String[] args) {
    Person p1 = new Person();
    Person.count++;
}

public class Person {
    static int count;

    public Person() {
        count++;
    }
}

클래스 상수

public class CodeitConstants {
    public static final double PI = 3.141592653589793;
    public static final double EULERS_NUMBER = 2.718281828459045;
    public static final String THIS_IS_HOW_TO_NAME_CONSTANT_VARIABLE = "Hello";

    public static void main(String[] args) {
        System.out.println(CodeitConstants.PI + CodeitConstants.EULERS_NUMBER); // 5.859874482048838
    }
}