The Java Program: Employee02.java
1 // Employee02.java -- generic sorting using an interface
2
3 interface Sortable02 {
4 public abstract boolean compare (Sortable02 b);
5 }
6
7 final class Sort {
8 public static void sort (Sortable02 [] a) {
9 int i=0,j=0;
10 // ...
11 a[i].compare (a[j]);
12 // ...
13 }
14 }
15
16 class Employee02 extends Object implements Sortable02 {
17 public int salary;
18 public boolean compare (Sortable02 b) {
19 Employee02 e = (Employee02) b;
20 return (salary < e.salary);
21 }
22 public static void main (String [] args) {
23 Employee02 [] a = {};
24 Sort.sort (a);
25 }
26 }
27