class A{
...
class B{
...
}
...
}
class Outer{
class InstanceInner{}
static class StaticInner{}
void myMethod(){
class LocalInner{}
}
}
인스턴스 클래스
static 클래스
지역 클래스
익명 클래스
class Ex7_12{
class InstatnceInner{
int iv = 100;
//static int cv = 100; //에러! static 변수를 선언 할 수 없다.
final static int CONST = 100; // final static은 상수이므로 허용
}
static class StaticInner{
int iv = 200;
static int cv = 200; //static 클래스만 static멤버를 정의 할 수 있다.
}
void myMethod(){
class LocalInner{
int iv = 300;
static int cv = 300; //에러! static변수를 선언 할 수 없다.
final static int CONST = 300;//fianal static은 상수 이므로 허용 ,메서드 내에서만 사용 가능
}
}
}
class Outer{
private class InstanceInner{}
protected static class StaticInner{}
void myMethod(){
class LocalInner{}
}
}
class Outer2{
int value = 10; //Outer.this.value
class Inner{
int value = 20; //this.value = 20;
void method(){
int value = 30; //value
System.out.println("value: "+value);
System.out.println("this.value"+this.value);
System.out.println("Outer.this.value: "+Outer.this.value);
}
}
}