public class PersonExample { public static void main(String[] args) { Person p0 = new Person(100); Person p1 = new Person(100); Person p2 = new Person(200); Person p3 = new Person(300); System.out.println(p0==p1); System.out.println(p0.equals(p1)); System.out.println(p1.compareTo(p2)); System.out.println(p3.compareTo(p1)); } } class Person implements Comparable { private int weight; public Person(int w) { weight = w; } public int compareTo(Object o) { return weight - ((Person) o).weight; } public boolean equals(Person p) { return p.weight==weight; } }