innerClass
Posted 2015. 4. 10. 15:51package chap10;
// 내부클래스 예제
// 1. 클래스 내부에 존재하는 클래스( 클래스 안에 클래스 )
// 2. 참조자료형, 객체화 가능
// 3.멤버( 변수, 메서드, 생성자, Object를 상속 )도 소유가능
// 4. 상속도 가능
// 5. 외부클래스의 멤버임. 외부클래스의 private 멤버에 접근이 가능
public class innerEx1 {
// 인스턴스 내부 클래스 : static 멤버를 가질 수 없다.
// 단, 상수는 허용
private int aaaaa = 10;
public class InstanceInner{
int iv = 100;
// static int cv = 10;
static private final int MAX = 100;
}
// static 내부 클래스
static class StaticInner{
int iv = 200;
static int cv = 1;
}
// local inner 지역 내부 클래스 : 메서드 내에서 선언된 클래스
void myMethod(){
class LocalInner{
int iv = 300;
// static int c = 10; // static 멤버를 가질 수 없다.
static final int MAX = 100;
}
LocalInner l1 = new LocalInner();
System.out.println(l1.iv);
System.out.println(LocalInner.MAX);
}
public static void main(String[] args) {
innerEx1 in = new innerEx1();
in.myMethod();
System.out.println( InstanceInner.MAX );
System.out.println( StaticInner.cv );
}
}
- Filed under : 카테고리 없음