1. static을 사용하면 메모리 할당을 한번만 하게되어 메모리 사용에 이점이 있습니다. 


2. static을 붙이면 같은곳의 메모리 주소만 바라보기 때문에 static 변수의 값을 공유하게 됩니다. 


예를들어


public class Count {

static int num = 0;

Count() {

this.num++;

System.out.println(this.num);

}

public static void main(String[] args) {

Count a = new Count();

Count b = new Count();

}

}


에서 결과는


1

2


가 나오게 됩니다. 


 

'자바' 카테고리의 다른 글

SOLID  (0) 2019.07.02
나머지연산자를 이용한 반복출력  (0) 2019.03.09
C언어와 자바의 차이점  (0) 2019.01.15
Interface와 Abstract  (0) 2019.01.13

+ Recent posts