내부클래스 세부.

2009. 6. 23. 16:42 - 에릭투스

l  중첩클래스 (내부클래스)

 

1)    정의 : class안에 있는 클래스

2)  종류

A.     Static nested class

B.     Non-static nested class

 

A. Static nested class

                          : 객체생성방식  : ex) outer.innerStatic is = new outer.innerstatic();

                                        : classname.내부클래스 변수 = new classname.내부클래스();

 

B. Non Static nested class(inner class)

                         

// 외부클래스 객체를 만들고

: 객체생성방식 : ex)Outer out = new Outer(); 

Outer.inner inner = out.new outer.inner(); // 외부객체소속의 객체를 다시만드는 것.

*중첩class는 마치 field처럼 사용. (so 접근제한자 모두 사용가능.);

 

 

 

 

l  Anonymous inner Class

마치 객체를 형변환하는 형태와 비슷

             Ex) Anon a = new Anon(){ };

 

원래 interface는 객체생성하지 못하지만,

Interface를 상속받고 있는 Anonymous 클래스 생성가능.

 

이름이 없는 클래스 기존의 클래스(인터페이스)를 클래스 내부에서 상속받아서 새롭게 정의 하는 클래스

Ex) anon a = new anon(){ 내부}

 

 

수고하셨습니다.

다른 카테고리의 글 목록

자바 기본 공부/기초 이론 카테고리의 포스트를 톺아봅니다