public class MyDate {
private int day;
private int year;
private int month;
public MyDate(int month ,int day,int year) {
this.month = month;
this.day = day;
this.year = year;
}
public boolean equals(Object obj){
if(this == obj) {
return true;}
else if(obj instanceof MyDate){
MyDate m1 = (MyDate)obj;
if(m1.day == this.day && m1.month == this.month &&m1.year == this.year) {
return true;
}else
return false;
}
else
return false;
}
}
public class TestMyData {
public static void main(String[] args) {
MyDate m1 = new MyDate(14,3,1976);
MyDate m2 = new MyDate(14,3,1976);
if(m1 == m2) {
System.out.println("m1 == m2");
}else {
System.out.println("m1 != m2");
}
if(m1.equals(m2)) {
System.out.println("m1 is equal to m2");
}else {
System.out.println("m1 is not equal to m2");
}
}
}