Java/Constructor (생성자)
생성자 정의하기
Bohemian life
2012. 4. 11. 13:26
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