Given:
class Vehicle {
int vno;
String name;
public Vehicle (int vno, String name) {
this.vno = vno,;
this.name = name;
}
public String toString () {
return vno + : + name;
}
}
and this code fragment:
Set<Vehicle> vehicles = new TreeSet <> ();
vehicles.add(new Vehicle (10123, Ford));
vehicles.add(new Vehicle (10124, BMW));
System.out.println(vehicles);
What is the result?
D
here , the vehical class is not implementing comparator interface and didnt define its compareto method or we can use comparator<vehicles> to add vehicals in the treeset.so while adding the vehicles in the tree set it results in compilation error