// Canonical example of top-down (interface) inheritance. import java.util.ArrayList; import java.util.Random; public class SortedArrayList> extends ArrayList { public void insert(int i, T o) { this.add(o); } public boolean add(T o) { super.add(o); java.util.Collections.sort(this); return true; } public T set(int i, T o) { super.set(i, o); java.util.Collections.sort(this); return o; } public static void main(String args[]) { Random r = new Random(); ArrayList a = new SortedArrayList();// This is the only place we // explicitly mention subclass for (int i=0; i<10; i++) { a.add(r.nextInt(100)); } } }