3초기억력

제어자)static 본문

자바_기초

제어자)static

잠수콩 2019. 6. 7. 13:52
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
// Static 은 객체 생성 X
//	클래스명.static 변수, 메서드명

//static int i;		//오류

class FF{
//	static int a;		//오류
	static int a = 900;
}

public class StaticEx {
	
	static int i;
	int i2 = 1;
	
	void func() {
		int i3 = 2;
		System.out.println("static > " + i);
		System.out.println("local1 > "+ i2);
		System.out.println("local2 > "+ i3);
	}

	public static void main(String[] args) {

		System.out.println(FF.a);		//class 의 static 변수는 클래스명.변수명 으로 접근가능
		
		System.out.println("==============");

		System.out.println(i);
//		System.out.println(i2);		//인스턴스 멤버에 직접적으로 접근 안됨, 사용 불가	
//		System.out.println(i3);		//인스턴스 멤버에 직접적으로 접근 안됨, 사용 불가	

		System.out.println("==============");
		
		StaticEx s1 = new StaticEx();
		s1.func();
		
	}

}

'자바_기초' 카테고리의 다른 글

접근제어자) private  (0) 2019.06.07
접근제어자) public  (0) 2019.06.07
GUI(awt) - Gridlayout  (0) 2019.05.27
GUI(awt) - Boarderlayout  (0) 2019.05.27
GUI(awt) - flowlayout  (0) 2019.05.27
Comments