영상
개념
package 스태틱1_개념;
class Test01 {
// 클래스영역의 변수의 종류
public int a; // non-static 변수 = 인스턴스 변수
public static int b; // static 변수 = 클래스 변수
static void test() {
System.out.println("!!");
}
}
public class 스태틱1_개념01_기본이론1 {
public static void main(String[] args) {
// static 키워드
// static 은 시작하자마자 바로 메모리에 생성이되서
// new 를 하지않아도 사용할수있다.
// static으로 생성한 변수에 접근하는법
// 클래스명.변수명 ==> Test01.b
Test01.b = 10;
System.out.println(Test01.b);
System.out.println("-------------------------------------");
// static으로 생성된 변수는 new 를 할때 새로 생성되지않는다.
Test01 t1 = new Test01();
t1.a = 20;
System.out.println(t1.a);
System.out.println(t1.b); // 같은결과가나온다. Test01.b 와 같다.
System.out.println("-------------------------------------");
Test01 t2 = new Test01();
t2.a = 30;
System.out.println(t2.a);
System.out.println(t2.b); // 위와 같다.
}
}
// 스태틱_개념01_기본이론1.main(null);
Java
복사