飞狐爷

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
import java.util.ArrayList;
import java.util.List;

class Phone {
    private String brand;
    private double price;
    public Phone(String brand, double price) {
        this.brand = brand;
        this.price = price;
    }
    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        if(obj == null){
            return false;
        }
        if(! (obj instanceof Phone)){
            return false;
        }
        Phone phone = (Phone) obj;
        return this.brand.equals(phone.brand) && this.price==phone.price;
    }
    @Override
    public String toString() {
        return brand + price;
    }
}
public class Hello{
    public static void main(String args[]) throws Exception{
        List<Phone> list = new ArrayList<Phone>();
        list.add(new Phone("红米",399));
        list.add(new Phone("黑米",499));
        System.out.println(list.get(1));
        
    }
}

 

posted on 2016-08-26 17:36  飞狐爷  阅读(163)  评论(0编辑  收藏  举报