public class Shallow_2_1 {
private int year;
private int month;
private int day;
// 主方法
public static void main(String[] args) {
Shallow_2_1 t = new Shallow_2_1(1998, 4, 16);
System.out.println(t.toString());
System.out.println(t.equals(t));
}
// 无参数构造函数
public Shallow_2_1(){
}
// 有参数构造函数
public Shallow_2_1(int year, int month, int day){
this.year = year;
this.month = month;
this.day = day;
}
// 生成set get方法
public int getYear(){
return year;
}
public void setYear(int year){
this.year = year;
}
public int getMonth(){
return month;
}
public void setMonth(int month){
this.month = month;
}
public int getDay(){
return day;
}
public void setDay(int day){
this.day = day;
}
// 生成toString方法,一般生成toString方法要重写
public String toString(){
return year + "/" + month + "/" + day;
}
// 生成equals方法,一般生成equals方法要重写
@Override
public boolean equals(Object obj) {
if(this == obj){
return true;
}
if(!(obj instanceof Shallow_2_1)){
return false;
}
Shallow_2_1 tt = (Shallow_2_1)obj;
return this.year == tt.year && this.month == tt.month && this.day == tt.day;
}
}