package com.atguigu.exercise3;
public class Order {
//属性
private int orderId;
private String orderName;
//构造器
public Order(){
}
public Order(int orderId,String orderName){
this.orderId = orderId;
this.orderName = orderName;
}
//方法
public int getOrderld() {
return orderId;
}
public void setOrderld(int orderId) {
this.orderId = orderId;
}
public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
public boolean equals(Object obj){
if(this == obj){
return true;
}
if(obj instanceof Order){
Order order = (Order)obj;
return this.orderId == order.orderId && this.orderName.equals(order.orderName);
}
return false;
}
}
package com.atguigu.exercise3;
public class OrderTest {
public static void main(String[] args) {
Order order1 = new Order(1001,"AA");
Order order2 = new Order(1001,"BB");
System.out.println(order1.equals(order2));
Order order3 = new Order(1001,"BB");
System.out.println(order2.equals(order3));
}
}