금일 스프링부트를 공부하던 중 객체를 생성하지 않고 static 메서드를 호출하는 경우를 확인했다.
ex)
class Party{
public static String getName(){
return "홍길동";
}
}
public class PartyPeople {
public static void main(String[] args){
System.out.println(Party.getName());
}
}
Party.getName() 이 부분에서, Party라는 객체를 생성 해야만 호출할 것이라 예상했는데 아니였다.
이유를 찾아보니 static의 경우 메모리에 한번 할당되어 프로그램이 종료될 때 해제되는 것이기 때문이였다.
주로 static 활용 사례는 아래와 같다.