Write a program to sort employees by their experience. Employee class is not allowed to implement any interface.

(Last Updated On: May 26, 2015)

Answer: For sorting employees we need to use either Comparable or comparator interface. Since, as per question, the Employee class is not allowed to implement any Interface, only option is, to create a new comparator class that implements Comparator interface.

And in “compare()” method of comparator class, write the comparison code for the employee class on the basis of experience.

Sample: