1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*
* inner class : outer class 멤버를 자유롭게 사용할 수 있게 해주는 것
* - member inner class
* - static inner class : 오직 한개.
* - local inner class :
* - annoymous inner class : 객체 만들려면 이름 쓰는데 이름 없음 그냥 new 하면 됨, 이벤트 처리도 같은 개념
*
* 1/4 자주 많이 씀
*
* class A{
* class b{
* }
* }
*
* 독립적으로 존재하는 객체 만드는 것이 아니라 a의 메소드 처럼 만드는 것
* 메소드 만들면 클래스 내에서 맘대로 쓸 수 있음 -> 밖에서 접근 가능
* but, 이너 클래스 같은 경우는 내 멤버로 인식해 아웃 클래스가 이너 클래스를 자유롭게 사용할 수 있음
*
* */
public class InnerClass {
//local inner class
private int a; //private지만 같은 클래스 내이기에 class B에서도 사용할 수있움
public InnerClass() {
System.out.println("Outer Class");
a=30;
}
class B{ //inner class 객체 생성 시 outer 클래스 통해서 만들어야해
public B() {
a=50;
System.out.println("Inner Class"+a);
}
}
public static void main(String[] a) {
InnerClass ic = new InnerClass(); //inner class 생성 법
InnerClass.B b = ic.new B();
InnerClass.B aa = new InnerClass().new B();
}
}
Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|