Talentica interview question

sort objects, static keyword use

Interview Answer

Anonymous

27 Mar 2026

import java.util. *; class Employee implements Comparable { int id; string name; Employee(int id, String name) { this.id = id; this.name = name; } @Override public int compareTo(Employee other){ return this.id - other.id; } @Override public String toString() { return id + ":" + name; } } public class SortExample { public static void main(String[], args0 { List list = new ArrayList(); list.add(new Employee(102, "Aditya")); list.add(new Employee(101, "Sharma")); Collection.sort(list); System.out.println(list); } }