2012년 7월 27일 금요일

JAVA 매개변수 메소드 사용법


public class MyDate{

private int day = 1;
private int month = 1;
private int year = 2000;

public MyDate(){
}

public MyDate(int day, int month, int year){
this.day = day;
this.month = month;
this.year = year;
}

public MyDate(MyDate Date){
this.day = Date.day;
this.month = Date.month;
this.year = Date.year;
}

public MyDate addDays(int more_days){
MyDate new_date = new MyDate(this);
new_date.day = new_date.day + more_days;
return new_date;
}

public void print(){
System.out.println("MyDate: " + Date + "-" + month + "-" + year);
}

}

public class TestMyDate {
public static void main(String[] args){
MyDate init_birth = new MyDate();
MyDate my_birth = new MyDate(22, 8, 1971);

init_birth.print();
my_birth.print();

MyDate next_week = my_birth.addDays(7);
next_week.print();
}
}

댓글 없음:

댓글 쓰기