1. 모든 객체의 메모리가 모두 같은 값이 된다.
예를 들어 객체 box 가 있다고 합시다
box 안에 static 으로 된 리스트가 있습니다.
public class box {
static List ls = new ArrayList();
public box(int a) {
for (int i = 0; i < 10; i++) {
ls.add(a);
}
}
}
그리고 이박스들을 불러옵니다
box a 랑 box b 로 다른 두개의 객체를 만들었습니다
public static void main(String[] args) {
box a = new box(1);
box b = new box(2);
// box a 는 1 b 는 2
// 하지만 둘다 1로 출력되
System.out.println("box a 는 1 b 는 2 : ");
System.out.println("box a : "+a.ls.get(1));
System.out.println("box b : "+b.ls.get(1));
// b 를 초기화 하고 2값을 넣었음
b.ls.clear();
b = new box(77);
System.out.println("box b 박스 리스트 초기화 / 77 넣음");
System.out.println("box a : "+a.ls.get(1));
System.out.println("box b : "+b.ls.get(1));
}
하지만 결과는 박스 하나에 ls 값을 바꾸니 다른 box 의 list 까지 변경된것이다.

2.인스턴스를 생성하지 않아도 호출이 가능
그냥 바로 불러서 쓸수있음
public class main {
static void sayhello(){
System.out.println("Hello!");
}
public static void main(String[] args) {
sayhello();
}
}
'Spring > Spring 기본 도구 복습' 카테고리의 다른 글
| Rest template / URI component Builder (0) | 2024.03.23 |
|---|---|
| SpringData JPA 페이징 심화 (0) | 2024.03.05 |
| 02-05 til 최신 버전 Spring 3.2.2 사용 할때 주의점. + Spring security 조금 (0) | 2024.02.05 |
| 01-02-2024 (0) | 2024.02.01 |
| 간단한 Firebase(서치 엔진 만들기 .html / css/ js / firebase. (2023.12.26) (1) | 2023.12.26 |