티스토리 뷰


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

인스턴스 변수에 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+" 생성되었다잉");

}

}




'java,web study > 2주차 (7월 8일~14일)' 카테고리의 다른 글

객체간 형변환 (다형성 관련)  (0) 2013.07.11
재귀함수를 이용한 팩토리얼 구현  (0) 2013.07.10
인터페이스의 상속  (0) 2013.07.10
객체 복사  (0) 2013.07.09
Call Stack 예제  (0) 2013.07.09
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함