내용 |
public class TestMemberInner {
public static void main(String[] args) {
// Outer1 out1 = new Outer1();
// Outer1.Inner1 inner1 = out1.new Inner1();
Outer1.Inner1 inner1 = new Outer1().new Inner1();
inner1.doInner1();
doSomething(new Inter1() {
public void doInter() {
System.out.println("익명 클래스의 메서드 실행");
}
});
}
public static void doSomething(Inter1 obj) {
System.out.println("인터페이스를 전달받는 메서드");
obj.doInter();
}
}
interface Inter1 {
void doInter();
}
class Outer2 {
void doOuter2() {
int a = 20; // final 변수
class Inner2 { // Local Inner class
void doInner2() {
System.out.println(a);
System.out.println("doInner2");
}
}
Inner2 inner2 = new Inner2();
inner2.doInner2();
}
}
class Outer1 {
int a = 10; // instance 변수
class Inner1 { // inner class, Member Inner class
int a = 20; // instance 변수
void doInner1() {
int a = 30;
System.out.println(a);
System.out.println(this.a);
System.out.println(new Outer1().a);
}
}
} |