class MyDate2{//생성자 정의하기 private int year; private int month; private int day; //없어도 됨 (자동으로됨) public MyDate2(){ System.out.println("[생성자] : 객체가 생성될 때 자동 호출됩니다."); year=2011; month=12; day=16; } public void print(){ System.out.println(year + "/" + month + "/" +day); } } public class ConstructorTest02 { public static void main(String[] args){ MyDate2 d = new MyDate2(); d.print(); } }
[생성자] : 객체가 생성될 때 자동 호출됩니다.
2011/12/16
'Java > Constructor (생성자)' 카테고리의 다른 글
생성자 오버로딩 (0) | 2012.04.11 |
---|---|
은닉화 생성자 오버로딩 (0) | 2012.04.11 |
생성자 은닉화 캡슐화 (0) | 2012.04.11 |
참조 호출 Call by reference (0) | 2012.04.11 |
생성자 정의와 호출 (0) | 2012.04.11 |