<aside> 📎 ITEM4 인스턴스화를 막으려거든 private 생성자를 사용하라

</aside>

정적(static) 필드(변수)

class KimFamily { static String lastname = "김"; }

public class Study {
    public static void main(String[] args) {
        KimFamily A = new KimFamily();
        KimFamily B = new KimFamily();
    }
}

정적(static) 메서드

class Counter  {
    static int count = 0;
    Counter() { count++; }
    public **static** int **getCount**() { return count; }
}

public class Sample {
    public static void main(String[] args) {
        Counter c1 = new Counter();
        Counter c2 = new Counter();

        System.out.println(Counter.getCount());
    }
}

정적 메서드와 정적 필드만으로 구성된 클래스


Solution

public class UtilityClass {
		// 인스턴스화 방지용 생성자 입니다.
		private UtilityClass { throw new AssertionError(); }
}