package New_Dao;
public class MyDate {
public MyDate(int year,int month,int day){
this.year=year;
this.month=month;
this.day=day;
}
int year;
int month;
int day;
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;
}
@Override
public boolean equals(Object obj) {
int flag = 1;
//值比较instanceof
if (obj instanceof MyDate){
MyDate md = (MyDate) obj;
flag=0;
if (this.year != md.year){
flag +=1;
}
if (this.month != md.month){
flag +=1;
}
if (this.day != md.day){
flag +=1;
}
}
if (flag == 0 ){
return true;
}else {
return false;
}
}
//重写父类方法
@Override
public String toString() {
String str = this.year + “-” + this.month + “-” + this.day;
return str;
}
}
package New_Main;
import New_Dao.MyDate;
import New_Dao.Order;
import New_Dao.Person;
import New_Dao.Student;
public class Test_Main {
public static void main(String[] args) {
// Student s = new Student();
// Person p = new Person()
// Order o = new Order(123,“root”);
// Order o1 = new Order(123,“root”);
// System.out.println(o.equals(o1));
//装箱
// Integer i = new Integer(111);
// Integer i = new Integer(“123”);
// Integer i = new Integer(“qwe”); //因为不是数字类型不能装箱
// Integer i = new Integer(111);
//拆箱
// int i0= i.intValue();
// System.out.println(i0);
// Integer i1 = 111; //自动装箱
// int i2= i1; // 自动拆箱
// System.out.println(i2);
// int i = Integer.parseInt(“123”); //字符串转成基本数据类型
// float f = Float.parseFloat(“0.44”);
// boolean b = Boolean.parseBoolean( “false”);
//
// String istr = String.valueOf(i); //基础数据类型转字符串
// String fstr = String.valueOf(f);
// String bstr = String.valueOf(b);
MyDate m = new MyDate(2030,12,12);
System.out.println(m.toString()); //父类方法默认输出对象内存地址
System.out.println(m); //默认调用toString 方法
}
}