年为参数的构造方法,(2) 以年和月为参数的构造方法,(3) 以年月日为参数的构造方法。以分别(2019) ,(2019,3),(2016,3,24) 为参数创建三个Date对象。

定义一个Date类,包含三个成员变量year, month,day,分别定义(1)以年为参数的构造方法,(2) 以年和月为参数的构造方法,(3) 以年月日为参数的构造方法。以分别(2019) ,(2019,3),(2016,3,24) 为参数创建三个Date对象。


//变量
private int year;
private int month;
private int day;

//构造方法
//无参数构造方法
public Date(){}

//年
public Date(int year){
   this.year = year
}
//年,月
public Date(int year, int month){
   this.year = year;
   this.month = month;
}
//年月日
public Date(int year, int month, int day){
     this.year = year;
     this.month = month;
     this.day = day;
}

//使用main方法输出三个对象
//方法名称我就不写了,手机写的难受,你自己记得下面代码放main运行方法里面去就好了

//new一个Date类的对象,记得导包别导错了
Date date1 = new date(2019);
Date date2 = new date(2019, 3);
Date date3 = new date(2019, 3, 24);
//然后自己输出一下date对象就行了