package study;
public class StaticInner {
int a=10;
private int b=100;
static int c=200;
static class Inner {
//어쩔 수 없이 내부 클래스를 static으로 선언해야 할 경우가 있다.
//그건 바로 내부 클래스의 멤보들 중 하나라도 static 멤버가 있을 때다.
static int d=1000; // static 멤버
public void printData() {
// StaticInner s = new StaticInner();
// System.out.println("int a : " + s.a);
// System.out.println("int a : " + a); // 오류
// System.out.println("private int b : " + b); // 오류
System.out.println("static int c : " + c);
System.err.println("static int d : " + d);
}
}
public static void main(String[] args) {
// 또 다른 독립된 객체에서 static 내부 클래스 생성할 때
StaticInner.Inner inner = new StaticInner.Inner();
inner.printData();
// StaticInner라는 외부 클래스 내에서 생성 할 때
//Inner inner = new Inner();
//inner.printData();
}
}
'IT > 자바' 카테고리의 다른 글
Anonymous(익명) 내부 클래스 참조변수가 없는 경우 (0) | 2018.05.09 |
---|---|
Anonymous(익명) 내부 클래스 참조 변수의 이름이 있는 경우 (0) | 2018.05.09 |
LocalInner 내부 클래스 (0) | 2018.05.08 |
열거형 예제 3 (0) | 2018.05.08 |
열거형의 활용 (0) | 2018.05.08 |