public class Date {
private int year;
private int month;
private int day;
public Date() {
}
public Date(int year) { -------构造方法1
this();//调用无参构造方法
this.year = year;
}
public Date(int year, int month) { -----构造方法2
this(year);//调用了构造方法1
this.month = month;
}
public Date(int year, int month, int day) {------ 构造方法3
this(year, month); //调用了构造方法2
this.day = day;
}
public void fun() {
System.out.println(year + "年" + month + "月" + day + "日"
);
}
}
class TestDate {
public static void main(String[] args) {
Date date = new Date(2001, 10, 30);
date.fun();
}
}
输出结果:2001年10月30日