->Code, Data 영역
public class ClassVariable_02 {
//인스턴스 변수
private int num;
//클래스 변수
public static String city = "Seoul";
}
-------------------------------------------------
public class ClassVariableEx {
ClassVariable_02 cv01 = new ClassVarialbe_02();
ClassVariable_02 cv02 = new ClassVarialbe_02();
cv01.setNum(12345);
System.out.println(cv01.getNum()); ➡ 12345
System.out.println(cv02.getNum()); ➡ 0
//인스턴스 변수라서 각각 생성된 객체 내에 변수공간이 따로 존재
ClassVariable_02 cv03 = new ClassVarialbe_02();
ClassVariable_02 cv04 = new ClassVarialbe_02();
cv03.city = "Busan";
System.out.println(cv03.city); ➡ Busan
System.out.println(cv04.city); ➡ Busan
//city는 static으로 제한한 클래스 변수라 여러 객체가 있어도 변수공간은 단 하나만 존재 ➡ 값을 변경하면 다른 객체에서도 영향을 받음
//static 변수는 static한 방식으로 접근해야 함
ClassVariable_02.city = "Incheon";
//클래스 변수(정적변수)를 정적인 방법으로 접근
}
->Stack영역
