import java.util.*; class A implements Comparable { int data; public A (int d) { data = d; } public int compareTo (Object obj) { // Cast obj to A. // Then compare data to the data part of the parameter obj. // if data is equal than the parameter's data, return 0, // if less, return -1. // otherwise return 1. // WRITE YOUR CODE HERE } public String toString () { return ""+data; } } public class CompInterfaceExample { public static void main (String[] argv) { A[] a = new A [3]; a[0] = new A (5); a[1] = new A (4); a[2] = new A (5); System.out.println (a[0].compareTo(a[1])); // Prints 1 // Draw memory picture inside compareTo() just before returning here. System.out.println (a[0].compareTo(a[2])); // Prints 0 System.out.println (Arrays.toString(a)); // Original order. Arrays.sort (a); System.out.println (Arrays.toString(a)); // Sorted 4,5,5 } }