编写Order类,有int型的orderId,String型的orderName,相应的getter()和setter()方法,两个参数的构造器,重写父类的equals()方法:public boolean equals(Object obj),并判断类中创建的两个对象是否相等。
public class Test {
public static void main(String[] args){
Order o1 = new Order(123,"a");
Order o2 = new Order(123,"a");
System.out.println(o1.equals(o2));
}
}
public class Order {
public Order(int orderId,String orderName){
this.orderId=orderId;
this.orderName=orderName;
}
int orderId;
String orderName;
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
orderName = orderName;
}
public boolean Order(Object obj) {
boolean flag=false;
if(obj instanceof Order){
Order o=(Order) obj;
if(this.orderId==o.orderId&&this.orderName.equals(o.orderName)){
return true;
}
}
return false;
}
}