doublemetal 2013. 7. 10. 20:17


클래스 변수는 해당 클래스가 공통으로 사용하는 변수를 말하며 

인스턴스 변수에 static 예약어를 사용한다. 


//클래스 변수를 이용한 제목을 지정하지 않은 문서의 번호 매기기

package afternoon;


public class DocumentTest {


public static void main(String[] args) {

// TODO Auto-generated method stub

Document dc = new Document();

Document dd = new Document("Class Define");

Document de = new Document();

Document df = new Document("Serial Test");

Document dg = new Document();

Document dh = new Document();

}


}


class Document {

static int count = 1; //제목없음으로 명명된 문서의 번호

String do_name;


Document() {

this("제목없음 " + count++);

}


Document(String n) {

do_name = n;

System.out.println("문서 : "+do_name+" 생성되었다잉");

}

}