创建一个日期类Date,包括有数据成员为year、month、day分别表示年、月、日;有两个构造函数,其中一个没参数,一个有个参数;一个公有的输出日期的方法。编写时间测试类DateTest,在主方法中创建两个对象,一个没有参数,一个没公有参数,并通过调和对象输出日期。
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import java.util.HashMap;
/**
* @title: test
* @Author lwl
* @Date: 2021/12/20 18:24
* @Version 1.0
*/
public class Date {
private Integer year;
private Integer month;
private Integer day;
public Date(Integer year, Integer month, Integer day) {
this.year = year;
this.month = month;
this.day = day;
}
public Date() {
}
@Override
public String toString() {
return "Date{" +
"year=" + year +
", month=" + month +
", day=" + day +
'}';
}
public static void main(String[] args) {
Date AllArgsConstructor = new Date(1,2,3);
System.out.println(AllArgsConstructor);
Date NoArgsConstructor = new Date();
System.out.println(NoArgsConstructor);
}
}