<aside> 📌 class?우리가 가장 많이 만나는 class다. JVM공부를 하며 class가 어디에 할당되고 어떻게 쓰이고 언제 로딩 되고 뭐 이런 건 알게 되었다. 그럼 정의 방법은 뭘까? 사실 알고는 있는데 간략하게 정리하려고 한다.

</aside>


class가 뭐임?

<aside> 📌 class란? 정말 추상적인 이야기다. ORACLE 튜토리얼에서 찾아본 결과 class의 의미는 다음과 같이 정의 하고 있다. In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created. 대충 번역하자면 많은 개별 개체를 찾을 수 있는데, 뭐 자전거를 예로 들면 동일한 제조사에 다양한 자전거가 존재할 수 있다. 각 자전거는 동일한 청사진으로 제작되었으므로 동일한 구성 요소(페달, 브레이크, 프레임…)를 포함한다. 자전거를 만드는 청사진 즉, 자전거의 기본 틀을 class라 부른다. 라고 되어있다.

</aside>

<aside> 😅 내가 생각하는 class는 틀이다. 틀과 틀을 통해서 나온 결과는 다른 것이다. 물론 내가 금형을 만졌던 사람이라 이 개념이 좀 익숙한 것 같다.

</aside>


대충 느낌은 알았고 class는 어케만들어?

클래스의 구성요소

public class Main {

    public static void main(String[] args) {
        new Main();
    }

    static {
        System.out.println("static 초기화 블록");
    }
    static String s = Main.staticMethod();

    {
        System.out.println("인스턴스 초키화 블록");
    }

    public Main() {
        System.out.println("생성자");
    }
    public static String staticMethod(){
        System.out.println("static 메서드");
        return "할당 문자열";
    }
}

CONSOLE RESULT

static 초기화 블록 1
static 메서드 2
인스턴스 초키화 블록 3
생성자 4

// 1과 2는 순서에 따라 조금 바뀌는 것 같다.

<aside> 😅 추가적으로 알면 좋은 사항은 class이름을 만드는 방법이다. 클래스 및 인터페이스

</aside>

Naming Conventions in Java - GeeksforGeeks

Java Naming Conventions - Javatpoint

*Inner Class*

*Local Class*

*Static Class*

*Anonymous Class*